question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding Pagination on Ember Data HasMany Links using PagedRemoteArray

See original GitHub issue

in my afterModel I do something like this

 var parentRecordType = model.constructor.typeKey;
 var parentRecordId = parseInt(model.id, 10);
 var invoicesOptions = { parentRecordType: parentRecordType, parentRecordId: parentRecordId, modelName: 'invoice', store: this.store, page: 1, perPage: 10 };

 return Ember.RSVP.hash({
       filteredInvoices: PagedRemoteArray.create(invoicesOptions),
  });

I made some moderations to the fetchContent method in paged-remote-array.js

    var parentRecordType = this.get('parentRecordType');
    var parentRecordId = this.get('parentRecordId');
    var ops = this.get('paramsForBackend');
    var res;
    var url;

    if( Ember.isEmpty(parentRecordType) || Ember.isEmpty(parentRecordId) )
    {
        res = store.find(modelName, ops);
    }
    else
    {
       url = store.adapterFor(parentRecordType).buildURL(parentRecordType, parentRecordId) + '/' + store.adapterFor(parentRecordType).pathForType(modelName);
       res = Ember.$.get(url, ops);
    }

this will allow me to add add /patients/1/ to the url before invoices

// WHAT I WANT: http://localhost:3000/api/v1/patients/1/invoices?page=1&per_page=10

the tricky thing is I can’t do

res = Ember.$.get(url, ops);

as I get this error back

Uncaught Error: Assertion Failed: ArrayProxy expects an Array or Ember.ArrayProxy, but you passed object 

debugging into ember data shows me

store.find(modelName, ops) goes into  findQuery and returns a promiseArray

I am pretty sure I will be to get this working with some more code but any suggestions on the best way to add pagination on has many links depending on the page I visit?

Issue Analytics

  • State:open
  • Created 9 years ago
  • Reactions:1
  • Comments:21 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
eguneyscommented, Dec 11, 2014

I have this model:

export default DS.Model.extend({
  articles: DS.hasMany('article', { async: true }),
  name: DS.attr('string'),
  email: DS.attr('string')
});

and this route:

export default Ember.Route.extend(RouteMixin, {
  model: function(params) {
    return this.store.find('author', params.author_id);
  }
});

this makes the request: /authors/1 and /authors/1/articles. The last request is paginated, How can I integrate pagination for models loaded async with hasMany?

0reactions
brunoocasalicommented, May 7, 2019

A lot of time has passed since this issue was opened, does anyone have any news?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Manual Pagination in Ember Data Relationships
I'm trying to figure out a good way to properly paginate through a relationship in an ember-data model. I have a slight preference...
Read more >
mharris717/ember-cli-pagination - GitHub
Allows configuration of param names for page/perPage/total_pages. Once the data is loaded, you may iterate over a PagedRemoteArray as you would a normal...
Read more >
how to paginate ember-data relationships - Stack Overflow
Here is a fiddle to illustrate what I'm trying to accomplish in the IndexController . I have no idea what the "ember way"...
Read more >
ember-data-has-many-query - npm
Ember data addon for querying async has-many relationships using query parameters. Latest version: 0.3.1, last published: 3 years ago.
Read more >
Pagination in Ember with a JSON API Backend
To paginate the primary data, supply pagination links in the top-level links object. […] The following keys MUST be used for pagination links:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found