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