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.