Issue loading object with ember data and hasMany



I’m new to Ember Data so apologies if this has been answered already.

I have a many-to-many relationship between Roles and Users. I want to send a User’s roles when I call so that I can update them. By default Ember does not seem to send the role_ids along with the User object, so I added a serializer for serializeHasMany (below)

This works correctly for sending data, now my role_ids are there, but it breaks loading the User. When I look at a User the User no longer has roles set. If I delete my serializer the User is correctly loaded with roles, but save() doesn’t send roles.

serializeHasMany: function(record, json, relationship) { var key = relationship.key, jsonKey = Ember.String.singularize(key) + ‘_ids’; json[jsonKey] = []; record.get(key).forEach(function(item) { json[jsonKey].push(item.get(‘id’)); }); return json; }

Roles are configured on my User object as: roles: DS.hasMany(‘role’, { embedded: ‘always’, async: true})


I’ve tried experimenting by setting async to false and just using embedded ‘always’ but it doesn’t make a difference.