0

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'),
});

ただし、これは と の関係を捉えていませIngredientAdditionIngredientDS.hasMany各 IngredientAddition には正確に 1 つの があるため、適切ではないようですIngredientDS.belongsToライフIngredientサイクルはIngredientAddition.

この情報を取得するにはどうすればよいですか? ソースを見ましたが、とember-data以外の関係タイプが見つかりません。hasManybelongsTo

4

1 に答える 1

0

私はあなたがbelongsTo上の関係を望んでいると思いますIngredientAddition

App.IngredientAddition = DS.Model.extend({
  how:  DS.attr('string'),
  qty:  DS.attr('string'),
  ingredient: DS.belongsTo('App.Ingredient'),
  recipe: DS.belongsTo('App.Recipe'),
});

このように、関連するを指すIngredientAddition基礎があります。「所有」のセマンティクスは奇妙ですが、これはあなたが説明した関係を生み出す方法です。ingredient_idIngredientIngredientIngredientAddition

于 2013-03-06T21:49:38.530 に答える