Note that there are some explanatory texts on larger screens.

plurals
  1. POSub resources with emberjs + ember-data
    text
    copied!<p>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.</p> <p>Pretend I have two objects: <code>Post</code> and <code>Tag</code></p> <p>Calling <code>App.Post.find()</code> returns all the posts by <code>GET</code>ing <code>api.com/posts</code>, <code>App.Post.find(1)</code> is found at <code>api.com/posts/1</code>. This is good.</p> <p><code>App.Tag.find()</code> will return all the tags that are available at <code>api.com/tags</code>. <code>App.Tag.find(1)</code> will return the appropriate tag at the correct url. Also good.</p> <p>If I create new Posts via <code>App.Post.createRecord({...})</code> It will <code>POST</code> to the correct url. The same goes for creating <code>Tags</code>. So far everything is dandy.</p> <p><code>Tags</code> on a <code>Post</code> are embedded because they are "on" that post.</p> <pre><code>App.Adapter.map("App.Post", { tags: {embedded: 'always'} }); </code></pre> <p>During load, Ember-data does everything right and I'm still super happy.</p> <p>So my problem comes from adding a <code>Tag</code> to a <code>Post</code>. I would like to <code>PUT</code> or <code>POST</code> the tag object to <code>api.com/posts/1/tags</code> where the server will do all the server side things.</p> <p>Currently,</p> <ol> <li><p>Ember-data, with the <code>{embedded: 'always'}</code> config set, will send a <code>PUT</code> to <code>api.com/posts/1</code> with the entire <code>Post</code> object (with new <code>Tag</code> object included) as a JSON stringified string.</p></li> <li><p>Without the <code>{embedded: 'always'}</code> config set, ember-data will try to <code>PUT</code> the tag object to <code>api.com/tags</code> and will send in the <code>Tag</code> object with a <code>post_id</code> parameter so the server side can do all the server side things.</p></li> </ol> <p>I'd rather not do 1 because my server isn't set up that way. I'd rather not do 2 because <code>PUT/POST/GET</code>s on <code>api.com/tags</code> 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 <a href="http://developer.github.com/v3/issues/labels/#add-labels-to-an-issue" rel="noreferrer">Github v3 API for Labels &amp; Issues</a>.</p> <p>Does anyone know of a way of handling this with ember-data? Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload