0
Emberjs支持单向关系吗?想想看,我想存储有关的食谱信息有三种模式:Emberjs多对一单向关系
Ingredient
- 始终存在。给出
name
和description
。 - 没有“拥有”一种成分,也不应该在新引用时被复制,或者在引用被销毁时被销毁。他们只是是。
- 始终存在。给出
IngredientAddition
- 由时/谁添加的成分和数量
- 很多
IngredientAddition
对象可以使用相同成分的一个Ingredient
和信息。
Recipe
- 由许多
IngredientAddition
对象和辅助信息。
- 由许多
据我了解的东西,我的模型如下所示:
App.Ingredient = DS.Model.extend({
name: DS.attr('string'),
desc: DS.attr('string'),
});
App.IngredientAddition = DS.Model.extend({
how: DS.attr('string'),
qty: DS.attr('string'),
recipe: DS.belongsTo('App.Recipe'),
});
App.Recipe = DS.Model.extend({
desc: DS.attr('string'),
ingredients: DS.hasMany('App.IngredientAddition'),
});
然而,这并不能捕捉IngredientAddition
和Ingredient
之间的关系。 DS.hasMany
似乎并不合适,因为每种添加成分只有一个Ingredient
。 DS.belongsTo
不合适,因为Ingredient
的生命周期不是由IngredientAddition
的存在(或缺少)决定的。
如何捕获此信息?我查看了ember-data
来源,除hasMany
和belongsTo
之外,我找不到任何关系类型。
从查看Ember如何管理参考文献,当Ingredient改变时,不会出现“IngredientAddition”对象将被更新。绑定看起来像是单向的。 – 2013-03-08 00:09:12