Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I need to know how many rows of a specific resource (App.User) exist in total.

I tried to return it in response, but Ember complains about not mapped properties and is expecting only array of records (users: [ "john", "fred"]). I do not want to make an additional query to the server.

Is there any clean way to achieve this with Ember?

like image 251
korCZis Avatar asked Sep 25 '12 18:09

korCZis


2 Answers

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.

like image 80
inertia Avatar answered Oct 16 '22 05:10

inertia


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

like image 44
Robin Clowers Avatar answered Oct 16 '22 05:10

Robin Clowers