So I'm having (what i think is) a general problem w/ Ember-data. I'm wondering how to properly customize the adapter to adapt to the following situation.
Pretend I have two objects: Post and Tag
Calling App.Post.find() returns all the posts by GETing api.com/posts, App.Post.find(1) is found at api.com/posts/1. This is good.
App.Tag.find() will return all the tags that are available at api.com/tags. App.Tag.find(1) will return the appropriate tag at the correct url. Also good.
If I create new Posts via App.Post.createRecord({...}) It will POST to the correct url. The same goes for creating Tags. So far everything is dandy.
Tags on a Post are embedded because they are "on" that post.
App.Adapter.map("App.Post", {
tags: {embedded: 'always'}
});
During load, Ember-data does everything right and I'm still super happy.
So my problem comes from adding a Tag to a Post. I would like to PUT or POST the tag object to api.com/posts/1/tags where the server will do all the server side things.
Currently,
Ember-data, with the
{embedded: 'always'}config set, will send aPUTtoapi.com/posts/1with the entirePostobject (with newTagobject included) as a JSON stringified string.Without the
{embedded: 'always'}config set, ember-data will try toPUTthe tag object toapi.com/tagsand will send in theTagobject with apost_idparameter so the server side can do all the server side things.
I'd rather not do 1 because my server isn't set up that way. I'd rather not do 2 because PUT/POST/GETs on api.com/tags should really be for the "Tag management" portion of my application, and not really applying tags to posts. Another example of this behaviour is in the Github v3 API for Labels & Issues.
Does anyone know of a way of handling this with ember-data? Thanks!