Ember Data's moved on quite a bit since I wrote my pull request, so I'd need to do it again. I've decided to lay out the case here and if you and the other members of the team feel it's a good idea then I'll do it again.
Here's the approach that I'm advocating:
- Whenever the store asks the adapter to fetch some records a
Requestobject (a new class) is created that contains the information required to request another page of results. - The
Requestobject is also used to contain thesinceTokenthat's currently there - The
metaobject that's returned from the server is then attached to theRequestobject, which is attached to the returnedRecordArrayso that downstream users of theRecordArray(eg.ArrayControllers) have access to the page number, page size and the total number of records RecordArrays would have two new methods:fetchPage()andfetchMore(), which would use the information in theRequestobject to perform another fetch from the server.- Adapters can control the parameter names that are used for pagination, and can also specify a default page size. By default adapters would not ask for any paging from the server unless requested in the call to
store.find...().
I've implemented this on the findQuery() method, and it wouldn't be hard to extend the approach to the other find...() methods (findMany(), findHasMany() et al). I've used this approach to implement normal paging, and an "infinite scroll" approach, and it's very simple and works really well.
I think this is the right solution, it's very minimal and allows for innovation to happen in userland. There's interest in this feature from the community. I think it'd be a real shame if Ember Data was released without basic support for pagination.
If we can get agreement on the right approach then I'll find the time to write the PR.
Sounds great. 👍 But how about linked relations? Say you have an
applicationrecord which has an async relation withpages. If you would do thisapplication.get('pages')it would make a call to/applications/1/pages. What if you need to paginate that?I've implemented a new method on the
Model, calledgetPaginated. You could sayapplication.getPaginated('pages', { page: 2 }).Did you made any progress with pagination in ED? It's been a time since you started this :P