Search code examples
sails.jsorientdbwaterlinesails-orientdb

Waterline Edges associations


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?


Solution

  • 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.