Skip to content

Instantly share code, notes, and snippets.

@zzarcon
Created July 9, 2014 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zzarcon/67c4181f3544e2d48fdf to your computer and use it in GitHub Desktop.
Save zzarcon/67c4181f3544e2d48fdf to your computer and use it in GitHub Desktop.
Serialized hasMany
App.ApplicationSerializer = DS.ActiveModelSerializer.extend({
serializeHasMany: function(record, json, relationship) {
var key = relationship.key;
var json_key = key.singularize().decamelize() + '_ids';
var relationshipType = DS.RelationshipChange.determineRelationshipType(
record.constructor, relationship);
if (relationshipType === 'manyToNone' || relationshipType === 'manyToMany' || relationshipType === 'manyToOne') {
json[json_key] = Ember.get(record, key).mapBy('id');
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment