Return count of total rows in ember data `find` or `findAll` request Return count of total rows in ember data `find` or `findAll` request json json

Return count of total rows in ember data `find` or `findAll` request


You need not make an additional query to the server. Once you get the data in datastore from the server, it stays there unless some record is dirty and you run a store.commit

So, after you get your records by saying

users = App.User.find()

you can simply do users.get('length') and you will get the length. When you do this, an additional query to the server is not generated.


If you want this in a handlebars template, you can do {{this.length}}.


I have solved this problem by implementing handleResponse in my adapter and modifying the response in the way that Ember expects it.

Let's say I get a response from server similar to this:

{  "count": 203,  "users": {...} //user data conforming to model } 

My handleResponse implementation looks like this:

handleResponse (status, headers, payload, requestData) {  let parsedPayload = {    users: payload.users,    meta: {      total: payload.count    }  };  return this._super(status, headers, parsedPayload, requestData);}

Then I can get the model metadata in a way Ember documentation specifies it