0

I just prepared a model which contains two vertices and one edge between them, v1, v2 and e1, while v1 is instance or vertex of class A, and v2 is vertex of class B. e1 is the instance of class E. I wanted to prepare schema in waterline for this kind of relation and the schema looks like this:

identity:'A',
connection:'ex1',
attributes:{
  title:'string',
  r : {collection:'B', through:'E', via:'A'}
}
identity:'A',
connection:'ex1',
attributes:{
  title:'string',
  r : {collection:'A', through:'E', via:'B'}
}

while if I use this schema to map into orientdb my fields it shows collection:'B' as a Linkset in A class. I just want to relate them via edges. Is there a way to skip mentioning collections and just build a relation which will map @rid of edge e1 into OUT or IN field of these classes as needed?

Travis Webb
  • 14,688
  • 7
  • 55
  • 109
Zeeshan
  • 375
  • 1
  • 3
  • 17

1 Answers1

0

xeeB, you don't mention which waterline adapter for OrientDB you are using (there are at least 3). I'll assume it's waterline-orientdb.

In your schema example, you are defining a "Many-to-many through" association but you are missing (or didn't share) the definition of the "through" model (example).

Finally, the simplest way to build relations between vertexes using edges is to use "Many-to-many" associations. You can do this with the following code snippet based on your own example:

// Model A
{
  tableName : 'A',
  identity : 'a',
  connection : 'ex1',
  attributes : {
    title : 'string',
    r : {
      collection : 'b',
      via : 'r',
      dominant : true
    }
  }
}
// Model B
{
  tableName : 'B',
  identity : 'b',
  connection : 'ex1',
  attributes : {
    title : 'string',
    r : {
      collection : 'a',
      via : 'r'
    }
  }
}

A full "many-to-many" association working example at: https://github.com/appscot/waterline-orientdb/blob/master/example/associations/many-to-many.js

UPDATE: waterline-orientdb is now named sails-orientdb.

Dário
  • 2,002
  • 1
  • 18
  • 28
  • Now My question is using 'populate' i can get the attributes of vertex of class B from A for example A.find().populate('r').exec(function(err,model){/*CODE*/}); but my requirements are if I am standing on vertex A I want to get the Edge attributes as well, is this possible through waterline-orientdb? – Zeeshan Mar 30 '15 at 08:06
  • Hi @xeeB, the way to do that in [waterline](https://github.com/balderdashy/waterline) (sails-orientdb is just an adapter for waterline) would be to use many-to-may through associations which unfortunately are not supported yet ([issue #705](https://github.com/balderdashy/waterline/issues/705)). So... your best option is to use sails-orientdb custom method [`.query()`](https://github.com/appscot/sails-orientdb#query-query--options-cb) and use a normal SQL query. – Dário Mar 30 '15 at 10:26