Emberjs は一方向の関係をサポートしていますか? 3 つのモデルを使用してレシピに関する情報を保存するとします。
Ingredient- 常に存在します。
nameと を与えdescriptionます。 - 成分を「所有」するものはなく、新しい参照で複製したり、参照が破棄されたときに破棄したりしてはなりません。彼らはただです。
- 常に存在します。
IngredientAdditionIngredient材料をいつ/誰が追加するか、および量の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以外の関係タイプが見つかりません。hasManybelongsTo