hasMany has big collection of items


#1

Hi!

My model “user” has big collection of linked “comments”

export default DS.Model.extend({
 comments: DS.hasMany('comment', {
  async: true
 }),
 .....

But I want to display all comments with pagination on user’s page. When I try to get them via

user.get('comments')

Ember loads all comments.

How to prevent this and load only needed comments with “skip” and “limit” for pagination?

Thank you!


#2

I used the ember-cli-pagination package. Of course, your back end will need to support pagination. Here’s a sample route using it.

import Ember from 'ember';
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
import PaginateMixin from 'ember-cli-pagination/remote/route-mixin';

export default Ember.Route.extend(AuthenticatedRouteMixin, PaginateMixin, {
  limit: 25,

  model: function(params) {
    params.paramMapping = {
      page       : 'page',
      perPage    : 'limit',
      total_pages: 'count'
    };

    return this.findPaged('agency', params);
  }
});

Yes, the options use both camelCase and snake_case for some reason.