How does the SANE stack represent parent/child relationships on a single model

别等时光非礼了梦想. 提交于 2020-01-05 11:37:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!