Adding Pagination on Ember Data HasMany Links using PagedRemoteArray
See original GitHub issuein 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:
- Created 9 years ago
- Reactions:1
- Comments:21 (16 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have this model:
and this route:
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?A lot of time has passed since this issue was opened, does anyone have any news?