Many-to-many association on the same model using Waterline & Sails.js

I am trying to create a many-to-many relationship on one model in Sail.js using Waterline. The model looks like this and is called "Disciplne" (ie Academic discipline):

module.exports = {

  attributes: {
    'name': {
        type: 'string',
        unique: true,
        required: true,
      lowercase: true
    },
    'users': {
        collection: 'user',
        via: 'discipline'
    },
    recommendations: {
        collection: 'recommendation',
        via: 'discipline'
    },
    related: {
        collection: 'discipline',
        via: 'related'  
    }
  }

};

      

Given here is the key related

with which I am trying to set up a many-to-many relationship that refers to other records in the model Discipline

. When I run this Sails.js a named connection table is automatically created discipline_related__discipline_related

which is as it should be I think. Then when I try to create a new discipline document with the corresponding ID, this is what happens.

First, I try to create a new discipline:

Creating the new discipline with related discipline specified

The identifier here refers to the existing discipline of "political science". The result, however, as you can see from the image, does not include the field related

. And if I then ask for the contents of this model, again the field related

does not appear:

End result in discipline model

The join table, however, is populated, but only contains one identifier reference, so there is not really a many-to-many relationship configured:

join table result

Does anyone know what I might be doing wrong here? Or does Waterline + Sails.js just not support this feature?

+3
orm sails.js models waterline


source to share


No one has answered this question yet

See similar questions:

6
Sails.js model: create 2 associations with error

or similar:

253
Doctrine2: Best Way to Handle Many-to-Many with Extra Columns in a Reference Table
3
Complexity using `populate` with` groupBy` and `sum` using Waterline query in Sails.js
2
Sails / Waterline Dissolve Not Working in a Join Table?
2
Waterline how to make a reverse index
1
Sails creating data in many ways
1
Sails.js Request waterline by association
1
Sails and Waterline: Include attributes from the join table via the
0
Get count of related posts in sailsjs
0
Boolean Attribute for Waterline Model
0
SailsJS / Waterline - How to use "string" index in models and associations?



All Articles
Loading...
X
Show
Funny
Dev
Pics