Feature Request: Handling Paginated HasMany Relationships

When retrieving a hasMany relationship that is loaded asynchronously, there is currently no way to pass query parameters to customize the way the relationship is retrieved.

For example, say we have a Post record which has many comments (potentially thousands), and we would like to fetch the comments in paginated sets. I have searched for a clean solution for this scenario and have had to fall back to bypassing the relationship altogether and calling a basic query:

this.store.query('comment', { post_id: 1, page: 1 });

I had to change my API to accept /comments?post_id=1&page=1 for this to work. Fortunately, I was able to do this, since I had access to modify the API I was working with, but not everyone has that access. And if the API endpoint were /posts/1/comments?page=1, there is currently no way (that I have found) to achieve this without circumventing the hasMany relationship. I actually don’t know how I would do this without just falling back to jQuery AJAX.

What I would really like to do is something like:

post.queryHasMany('comments', { page: 1 });

and for the store to pass the supplied hash as query parameters to the built URL as it does with query and queryRecord.

I have also noticed that Ember Data doesn’t seem to be storing the meta data that comes back from a findHasMany, which is something we would also need for the above situation to be of much value.

Many Ember Data users are working with APIs that they don’t control, and I feel like Ember Data should offer the flexibility to work with these APIs without significant effort. Most of my pains with Ember to-date have been with getting my Ember Data adapters and serializers customized to work with non-standard APIs or operations that Ember Data doesn’t support. I realize that part of this is just a documentation effort to explain in more detail how to customize or write our own adapters and serializers, which I could probably help out with. Otherwise, love Ember and Ember Data and all you guys are doing. Many cheers.

Just want to put a +1 on this feature request. I suspect it’s on some roadmap somewhere (I swear I’ve read about support for this on the JSON API Spec, but I can’t seem to find it)…but, would still love to see this happen sooner rather than later.


Same - it seems crazy that this hasn’t been catered for yet

Does anyone know a workaround for this?

+1 on this.

Until there is an “ember way”, this is the solution we’ve come up with: build an ID as a cache key, e.g.

App.PostCommentBatchRoute = Ember.Route.extend({
  model: function (params) {
    var id = [ params.post_id, params.page, params.sort ].join(',');
    return this.store.findRecord('postCommentBatch', id);

Then override the adapter’s buildURL to transform that ID into an API URL.

This add-on has been pretty solid so far and was easy to integrate: