I am trying to create a many-to-many relationship on one model in Sail.js using Waterline. The model is as follows and is called "Disciplne" (i.e. 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'
}
}
};
The key attributed here is related
, with which I am trying to setup a many-to-many relationship that refers to other records in the Discipline
model. When I run this Sails.js automatically creates a join table called discipline_related__discipline_related
, which is as it should be I think. Then when I attempt to create a new discipline document with a related id, here is what happens.
First, I try to create the new discipline:
The id here pertains to an existing discipline 'political science'. The result, however, as you can see from the image, does not include the related
field. And if I then query the contents of that model, again the related
field does not show up:
The join table, however, is populated, but contains only one id reference, so doesn't really set up the many-to-many relationship:
Does anyone know what I may be doing wrong here? Or does Waterline + Sails.js simply not support this functionality?