emberjs/data — pull request #1001 by ybart (2013-05-27 15:53:13+00:00)
Title: Embedded ids for hasMany associations

## Use Case

My use case is to implement a reflexive many-to-many association (p.e. user has-many coworkers), rather than exposing the boilerplate 'coworkers' model to Ember. On the server I would implement a User's serializer that sends a list of ids in a coworkers field. This part already works well with ember data until I want to mutate the association.

When I try to save the record, the association is not saved by Ember Data. After investigation I found that this is the expected behavior, but I did not found any parameter to embed the association without embedding the whole records.

## Current State

The ember data docs contains the following statement:

The default REST semantics are to only add a has-many relationship if it is embedded. If the relationship was initially loaded by ID, we assume that that was done as a performance optimization, and that changes to the as-many should be saved as foreign key changes on the child's belongs-to relationship.

I assume this might be valid for many use-cases, but I suggest to make embedding ids rather than the whole record available as an option as well.

## Proposal and discussion

I intend to implement this but I would first like to have your opinion whether this is the right way to solve this. If it's not what would be the right way.

If you believe as well that is the right way, I would like your opinion about the way I intend to do it. I suggest adding a new embedding type that could be called 'refs' alongside to 'always' and 'load'. This means adding support in RESTAdapter#addHasMany and RESTAdapter#serialize or JSONAdapter#serialize. Then adding conditions to skip record loading in DS.Adapter#didSaveRecord callback.

Thanks by advance for your interest and your comments.