使用旧版本的ember(1.7.1)和ember-data(1.0.0 beta 12)尝试升级到2.0。加载我的应用程序时,我收到以下警告:
警告:“App.QPAC”的有效负载包含以下未知密钥:[abs_parent_gbid,author,comments,course,follow,has_more_comments,is_announcement,more_comments_count,resource_uri,title]。确保它们已在您的模型中定义。
这是我的模型代码(除了post之外还有其他模型但是在这个实例中没有加载它们。)
App.Feedstory = DS.Model.extend({
global_id: DS.attr('string'),
story_type: DS.attr('string'),
story: DS.belongsTo('qPAC', {polymorphic: true}),
});
App.QPAC = DS.Model.extend({
global_id: DS.attr('string'),
global_code: DS.attr('string'),
body: DS.attr('string'),
});
App.Post = App.QPAC.extend({
title: DS.attr('string'),
is_announcement: DS.attr('boolean'),
author: DS.belongsTo('user'),
comments: DS.hasMany('comment'),
});
Ember检查器向我显示发现了Post类型的所有存储库对象,并且它在Post属性中显示正在加载正确的ID而不是其他属性。
警告说它正在寻找App.QPAC模型中的post属性,而不是App.Post。有什么想法吗?
编辑:添加了序列化程序和适配器
App.ApplicationAdapter = DS.RESTAdapter.extend({
namespace: 'api/v2'
});
App.FeedstorySerializer = DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
primaryKey: 'global_id',
attrs: {
pin: {embedded: 'always' },
story: {embedded: 'always'},
},
});
App.PostSerializer = DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
primaryKey: 'global_id',
attrs: {
author: {embedded: 'always' },
course: {embedded: 'always' },
pin: {embedded: 'always' },
comments: {embedded: 'always'},
follows: {embedded: 'always'},
},
normalize: function(type, hash, prop) {
if (Object.keys(hash.comments).length === 0) {
hash.comments = null;
}
if (Object.keys(hash.follows).length === 0) {
hash.follows = null;
}
return this._super(type, hash, prop);
},
});