Application-wide serializer
This commit is contained in:
parent
de8ac653f6
commit
37d7ca0029
2 changed files with 12 additions and 19 deletions
|
@ -9,6 +9,17 @@ export default DS.RESTSerializer.extend({
|
||||||
var belongsTo = snapshot.belongsTo(key);
|
var belongsTo = snapshot.belongsTo(key);
|
||||||
key = this.keyForRelationship ? this.keyForRelationship(key, "belongsTo", "serialize") : key;
|
key = this.keyForRelationship ? this.keyForRelationship(key, "belongsTo", "serialize") : key;
|
||||||
json[key] = Ember.isNone(belongsTo) ? belongsTo : +belongsTo.record.id;
|
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);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
});
|
});
|
|
@ -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'));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
Reference in a new issue