by dbushell on 4/25/13, 6:08 PM with 8 comments
by avolcano on 4/25/13, 7:15 PM
Anyways, as for the way you're handling relationships:
The RESTAdapter works like it does because it expects hasMany<->belongsTo relationships. In that relationship:
- It can load the child record from an array of IDs on the parent.
- When a child record is updated, it is saved back to the server without including the parent.
- When a child record is added, it only saves itself back to the server. The server is expected to handle adding that record to the parent resource.
- Similarly, when a child record is deleted, it is saved back to the server and the server should remove it from the parent resource.
Essentially, the client shouldn't need to save the list of children back to the server.
The downside of this is that this doesn't actually work in a hasMany<->hasMany relationship, because a record in that relationship does need to send back the list of resources - it's the same as the way a belongsTo record will include its parent.
Regardless, there's no obvious harm in overriding RESTAdapter to do this, and it shouldn't impact the way that a regular hasMany<->belongsTo relationship is handled. Just make sure that the client-side records always have a current representation of their relationships, or you might end up saving back incorrect versions of the records.
by benhowdle89 on 4/25/13, 6:27 PM
What's Ember? Do you mean Ember.js?