0
关联记录我有这样的设置:与Ember数据
App.MyModel = Em.Model.extend({
someValue: DS.attr('string'),
parent : DS.belongsTo('mymodel',{async:true, inverse:'rooms'}),
rooms : DS.hasMany('mymodel', {async:true, inverse:'parent'})
});
App.MyRoute = Em.Route.extend({
model:function(params){
var parent = this.store.find('mymodel', params.parent_id);
return this.store.createRecord('mymodel',{parent:parent});
}
});
params.parent_id
有我想要的ID,所以find()
应该返回正确的记录。
然后someValue
被绑定在模板的输入框中,输入后被调用的动作create
。
App.MyController = Ember.ObjectController.extend({
actions:{
create:function(){
this.get('model').save();
}
}
});
但是,当数据被发送到服务器,只someValue
有正确的数据,parent
是null
。
我不知道错误是在模型定义中还是在我设置关系的方式中。
如何正确设置记录关系?