Emberjs は一方向の関係をサポートしていますか? 3 つのモデルを使用してレシピに関する情報を保存するとします。
Ingredient
- 常に存在します。
name
と を与えdescription
ます。 - 成分を「所有」するものはなく、新しい参照で複製したり、参照が破棄されたときに破棄したりしてはなりません。彼らはただです。
- 常に存在します。
IngredientAddition
Ingredient
材料をいつ/誰が追加するか、および量の1つと情報で構成されています- 多くの
IngredientAddition
オブジェクトが同じ成分を使用できます。
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
各 IngredientAddition には正確に 1 つの があるため、適切ではないようですIngredient
。 DS.belongsTo
ライフIngredient
サイクルはIngredientAddition
.
この情報を取得するにはどうすればよいですか? ソースを見ましたが、とember-data
以外の関係タイプが見つかりません。hasMany
belongsTo