Application-wide serializer

This commit is contained in:
Matthew Dillon 2015-09-09 11:40:07 -07:00
parent de8ac653f6
commit 37d7ca0029
2 changed files with 12 additions and 19 deletions

View file

@ -9,6 +9,17 @@ export default DS.RESTSerializer.extend({
var belongsTo = snapshot.belongsTo(key);
key = this.keyForRelationship ? this.keyForRelationship(key, "belongsTo", "serialize") : key;
json[key] = Ember.isNone(belongsTo) ? belongsTo : +belongsTo.record.id;
}
},
serializeHasMany: function(snapshot, json, relationship) {
var key = relationship.key;
var hasMany = snapshot.hasMany(key);
key = this.keyForRelationship ? this.keyForRelationship(key, "hasMany", "serialize") : key;
json[key] = [];
hasMany.forEach((item) => {
json[key].push(+item.id);
});
},
});

View file

@ -1,18 +0,0 @@
import DS from 'ember-data';
import Ember from 'ember';
export default DS.RESTSerializer.extend({
isNewSerializerAPI: true,
serializeHasMany: function(snapshot, json, relationship) {
var key = relationship.key;
var hasMany = snapshot.hasMany(key);
key = this.keyForRelationship ? this.keyForRelationship(key, "hasMany", "serialize") : key;
json[key] = [];
hasMany.forEach((item) => {
json[key].push(+item.get('id'));
});
}
});