SANE堆栈如何在单个模型上表示父/子关系 [英] How does the SANE stack represent parent/child relationships on a single model
问题描述
如何在同一模型中表示父/子关系?
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具有。我想实现第一个选项。
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 ..."
如何在SANE堆栈的sails.js端设置?
How would I go about setting that up on the sails.js side of the SANE stack?
推荐答案
我不知道在客户端网站上需要做什么调整,但是我确信在Sails端这样做的唯一方法是设置一秒引用同一个表的模型。
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.
这篇关于SANE堆栈如何在单个模型上表示父/子关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!