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:
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:
The join table, however, is populated, but only contains one identifier reference, so there is not really a many-to-many relationship configured:
Does anyone know what I might be doing wrong here? Or does Waterline + Sails.js just not support this feature?
source to share
No one has answered this question yet
See similar questions:
or similar: