问题
How do I represent a parent/child relationship on the same model?
An example of this is a model representing a folder. A parent folder can have many children folders. But a child folder can only have one parent folder.
Ember.js has the concept of reflexive relations. I would like to implement the first option.
"... explicitly define the other side, and set the explicit inverse accordingly ..."
How would I go about setting that up on the sails.js side of the SANE stack?
回答1:
I'm not sure what adjustments you would need to make on the client site, however I'm pretty sure the only way to do this on Sails side is to setup a second model that references the same table.
This would allow you to have a table of items that has a one to many relationship on itself.
stuffA.js
module.exports = {
table:'stuff',
attributes: {
otherStuff : {
model: 'modelB'
}
}
}
stuffB.js
module.exports = {
table:'stuff',
otherstuff: {
collection : 'stuffA',
via: 'otherstuff'
}
}
I understand this may NOT answer your question since you asked how you would do this on a single model, but in case you you meant single Collection / Table.
来源:https://stackoverflow.com/questions/29903501/how-does-the-sane-stack-represent-parent-child-relationships-on-a-single-model