我很难在ember数据中保存一对多的关系.我有这样的关系:
App.ParameterSet = DS.Model
name: DS.attr("string")
regions: DS.hasMany("App.Region")
App.Region = DS.Model
name: DS.attr("string")
Run Code Online (Sandbox Code Playgroud)
如果我做这样的事情:
parameterSet = App.ParameterSet.find(5)
@transaction = @get("store").transaction()
@transaction.add(parameterSet)
region1 = App.Region.find(10)
region2 = App.Region.find(11)
parameterSet.set("name", "foo")
parameterSet.get("regions").pushObject(region)
@transaction.commit()
Run Code Online (Sandbox Code Playgroud)
然后我想看到带有这样的有效负载的PUT请求:
api/ParameterSets/5
{parameterSet: {name: "foo", regionIds:[10, 11]}}
Run Code Online (Sandbox Code Playgroud)
但相反,我得到了这个:
{parameterSet: {name: "foo"}}
Run Code Online (Sandbox Code Playgroud)
我不关心从孩子到父母的关系,但如果我添加parameterSet: DS.belongsTo("App.ParameterSet")到App.Region模型,那么我得到2个PUT请求到区域url的两个新关系,这不是我想要的.
我想这是一个多对多的关系,我不确定是否支持,但有关如何实现我所描述的任何想法?谢谢