获取最新的金丝雀版本,这将解决belongsTo
问题,但是因为hasMany
我尝试修改 ember-data 的代码,并且到目前为止有效,
将第 167 行更改为
if (relationshipType === 'manyToNone'
|| relationshipType === 'manyToMany'
|| relationshipType === 'manyToOne')
更新
更好的解决方案是序列化程序中的覆盖serializeHasMany
方法。
感谢@wycats(根据 github #1273上的讨论)
就像是
Deific.AppacitiveRESTSerializer = DS.RESTSerializer.extend({
//primary key is '__id' in appacitive, overriding default behaviour
primaryKey: '__id',
serializeHasMany: function(record, json, relationship) {
var key = relationship.key;
var relationshipType = DS.RelationshipChange.determineRelationshipType(record.constructor, relationship);
if (relationshipType === 'manyToNone' || relationshipType === 'manyToMany' || relationshipType === 'manyToOne') {
json[key] = record.get(key).mapBy('id');
// TODO support for polymorphic manyToNone and manyToMany relationships
}
}
});
Deific.Store = DS.Store.extend({
revision: 12,
adapter: DS.RESTAdapter.extend({
namespace: 'service',
defaultSerializer: 'Deific/appacitiveREST'
}),
});
暂时可以用这个。希望这可以帮助。