createRecord
永远不会创建belongsTo
对象。用于一对一关系的createRecord在余烬数据RC1(余烬数据修订版11)中失败
是否有任何解决方案创建子模型对象的情况下,有这样的关系Post-> hasOne -> Comment
和评论是嵌入总是里面的帖子。 。
这适用于Post -> hasMany -> Comments
(如烬数据,例如需要帮助,我们都坚持这一问题
App.Test = DS.Model.extend({
text: DS.attr('string'),
contact: DS.belongsTo('App.Contact')
});
App.Contact = DS.Model.extend({
id: DS.attr('number'),
phoneNumbers: DS.hasMany('App.PhoneNumber'),
test: DS.belongsTo('App.Test')
});
App.PhoneNumber = DS.Model.extend({
number: DS.attr('string'),
contact: DS.belongsTo('App.Contact')
});
App.RESTSerializer = DS.RESTSerializer.extend({
init: function() {
this._super();
this.map('App.Contact', {
phoneNumbers: {embedded: 'always'},
test: {embedded: 'always'}
});
}
});
/* in some controller code */
this.transitionToRoute('contact', this.get('content'));
下面的代码行的工作:
this.get('content.phoneNumbers').createRecord();
以下代码行失败:
this.get('content.test').createRecord();
这是错误:
Uncaught TypeError: Object <App.Test:ember354:null> has no method 'createRecord'
所以hasMany适用于createRecord,但1:1失败。难道我做错了什么 ?什么是正确的方式/是否不可能做到这一点?
@adrien coquio感谢,有关该问题的任何线索? – sudhanshu 2013-02-20 13:13:47
我们没有足够的信息来正确地查看您的问题。也许你可以尝试写一个[jsfiddle](http://jsfiddle.net/)来重现问题?或者添加一些你的代码示例,这将更明确? – 2013-02-20 13:32:18
@adrien coquio我希望我的编辑能帮助你。寻找帮助,我们坚持这一点。 – sudhanshu 2013-02-20 14:12:15