目前正在開發一個使用Ember-cli的應用程序,並且使用2個單詞和關係模型有一些困難。Ember cli - 由多個單詞和關係組成的模型(ember-data)
型號居民矚目
//models/residents-profile.js
DS.Model.extend({
firstName: DS.attr('string'),
lastName: DS.attr('string'),
picture: DS.attr('string'),
phone: DS.attr('string'),
gender: DS.attr('string'),
residentsAccount: DS.belongsTo('residentsAccount')
}
**型號居民賬戶**
//models/residents-account.js
DS.Model.extend({
email: DS.attr('string'),
password: DS.attr('string'),
profileId: DS.attr('number'),
residentsProfile: DS.belongsTo('residentsProfile', this.profileId),
});
對居民路線模型鉤:
//routes/residents.js
model: function() {
return Ember.RSVP.hash({
residentsProfile: this.store.find('residentsProfile'),
residentsAccount: this.store.find('residentsAccount')
})
}
由於儘快嘗試和fetc h只是居民的個人資料,我得到一個錯誤「居民。索引不能讀取財產'typeKey'」
但是,如果我從居民配置文件中刪除關係密鑰,並只打電話給居民配置文件數據被正確提取。
我使用的RESTAdapter和一個RESTful API,
這些模型被單獨返回和來自服務器的響應如下所示:
GET/residentsProfile { 「residentsProfiles」 :[{ 「ID」:20, 「圖片報」:空, 「手機」 日期null, 「名字」: 「洛奇」, 「姓氏」: 「巴爾博亞」, 「塊標識」:空, 「unitId」:null, 「createdAt」:「2014-09-17 19:54:28」, 「updatedAt」:「2014-09-17 19:54:28」, 「residentaccount」:[5 ] }] }
GET/residentsAccount { 「residentsAccounts」:[{ 「ID」:5, 「電子郵件」: 「[email protected]」, 「管理員」:假, 「resident」:true, 「profileId」:20, 「createdAt」:「2014-09-17 19:54:29」, 「updatedAt」:「2014- 09-17 19" 時54分29秒, 「residentsProfile」:[20] }] }
EDIT
除了由@ Kingpin2k提出的修改,這是點上,我使用setupcontroller以下列方式:
setupController: function(controller,
controller.set('residentsAccount', models.residentsAccount);
controller.set('residentsProfile', models.residentsProfile);
}
現在一切正常。
你是絕對正確的,我只是粘貼了我在編輯器中的任何東西(拼命地)試圖調試。所以肯定這是一個錯誤。我正在等待後端人員修復api來測試它,然後將您的答案標記爲正確。 非常感謝您的回覆! – bzlies 2014-09-19 15:30:26