mirror of
https://gitlab.silvrtree.co.uk/martind2000/project.git
synced 2025-01-10 23:45:07 +00:00
39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
import DS from 'ember-data';
|
|
import Ember from 'ember';
|
|
|
|
export default DS.JSONAPISerializer.extend({
|
|
serializeBelongsTo: function(record, json, relationship) {
|
|
var key = relationship.key;
|
|
var belongsTo = Ember.get(record, key);
|
|
key = this.keyForRelationship ? this.keyForRelationship(key, 'belongsTo') : key;
|
|
|
|
if (relationship.options.embedded === 'always') {
|
|
json[key] = belongsTo.serialize();
|
|
} else {
|
|
return this._super(record, json, relationship);
|
|
}
|
|
},
|
|
serializeHasMany: function(record, json, relationship) {
|
|
var key = relationship.key;
|
|
var hasMany = Ember.get(record, key);
|
|
var relationshipType = DS.RelationshipChange.determineRelationshipType(
|
|
record.constructor,
|
|
relationship);
|
|
|
|
if (relationship.options.embedded === 'always') {
|
|
if (hasMany && relationshipType === 'manyToNone' || relationshipType === 'manyToMany' ||
|
|
relationshipType === 'manyToOne') {
|
|
|
|
json[key] = [];
|
|
hasMany.forEach(function(item) {
|
|
json[key].push(item.serialize());
|
|
});
|
|
}
|
|
|
|
} else {
|
|
return this._super(record, json, relationship);
|
|
}
|
|
}
|
|
});
|
|
|