我有以下型號:堅持以燼數據父母和嵌入式記錄
App.Company = DS.Model.extend({
name: DS.attr('string'),
accounts: DS.hasMany('App.Account', {
inverse: 'company'
})
});
App.Account = DS.Model.extend({
login: DS.attr('string'),
first_name: DS.attr('string'),
last_name: DS.attr('string'),
email: DS.attr('string'),
password: DS.attr('string'),
password_confirmation: DS.attr('string'),
company: DS.belongsTo('App.Company')
});
公司被定義爲嵌入的帳戶:
DS.RESTAdapter.map('App.Account', {
company: { embedded: 'always' }
});
當我創建一個新帳戶,公司數據被正確地嵌入到帳戶數據中,並且我看到了我期望在服務器端的POST請求:
Started POST "/accounts" for 127.0.0.1 at 2013-06-27 13:30:53 +0200
Processing by AdminUsersController#create as JSON
Parameters: {"account"=>{"login"=>"fsdfdf", "first_name"=>"fgdfgh", "last_name"=>"[email protected]", "email"=>"[email protected]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "company"=>{"name"=>"gfdhgtrhzrh"}}}
但是,我也看到了公司本身的附加POST請求:
Started POST "/companies" for 127.0.0.1 at 2013-06-27 13:30:53 +0200
Processing by CompaniesController#create as JSON
Parameters: {"company"=>{"name"=>"gfdhgtrhzrh"}}
我設立的型號如下:
this.transaction = this.get('store').transaction();
var account = this.transaction.createRecord(App.Account, {});
account.set('company', this.transaction.createRecord(App.Company, {}));
當用戶點擊保存,我只是犯交易:
this.transaction.commit();
這是一個錯誤還是我做錯了什麼?花了相當一段時間,已經...
感謝您的幫助!
我通過將嵌入式配置更改爲DS.RESTAdapter.map('App.Account',{company:{embedded:'load'}});不知道爲什麼這實際上...... – marcoow
我認爲這是一個與belongsTo hasMany行爲如預期。有很多(甚至沒有孩子)你實際上使用關係來創建一個子記錄,但與belongsTo的關係爲null,所以你不能用this.get('company')創建它。createRecord –
我創建了一個拉請求我認爲修復它 - 我不明白爲什麼它不應該工作fir屬於就像它爲hasMany所做的那樣:https://github.com/emberjs/data/pull/1067 – marcoow