Ember-data - Sails - lazy selection of hasMany relationships on a specific url with no payload references or ids

Using classic models:

app/models/post.js
export default DS.Model.extend({
  comments: DS.hasMany('comment', {async: true})
});

app/models/comment.js
export default DS.Model.extend({
  post: DS.belongsTo('post', {async: true})
});

      

If I ask the sails API for

/ messages /

will return this payload:

[
  {
    "id": 1
  },
  {
    "id": 3
  }
]
// those are posts

      

No comment loading, not even a link. This is as intended. My API has a specific url to download post related comments (generated by standard sail blueprints):

/ posts / 1 / comment /

[
  {
    "post": 1,
    "id": 1,
  },
  {
    "post": 1,
    "id": 2
  },
  {
    "post": 1,
    "id": 3
  }
]
// those are comments

      

When I access comments associated with a post through a hasMany relationship, typically in a pattern like this:

<ul>
  {{#each comment in post.comments}}
    <li>My comment id: {{comment.id}}!</li>
  {{/each}}
</ul>

      

I would like ember to download my unclaimed comments at the specified url. There are 2 documented undocumented methods in RestAdapter that I could override for this: findHasMany and / or urlForFindHasMany, but these functions are never called by ember-data. I assume they want the link that the API needs to provide. I hacked my object controllers to get the data anyway, but I feel messy and I would rather move the logic to the adapter.

Is there a way to get the lazy loading of hasMany relationships through the API url of the following form?

/ parentModel /: identifier / relatedModel /

+3


source to share





All Articles