4
this.store.findAll('game').then(function(results){
   // RUN SOME OPERATION ON THEM
})

I would like to know how I can play with the results variable. I understand I can do

results.get('firstObject') // returns the first object.

I'd like to know everything else I can do with it. Is there any api documentation for the results collection?

Thanks!

Prakash Raman
  • 13,319
  • 27
  • 82
  • 132

2 Answers2

10

From ember guides,

The below methods, will return the Promise, it will be resolved to Record or RecordArray.

store.findAll() returns a DS.PromiseArray that fulfills to a DS.RecordArray.
store.findRecord returns a promise that will be resolved with the record.
store.query() returns a DS.PromiseArray in the same way as findAll.

The below two are synchronus method, it will retrieve what is available in the store and returns record itself. it will not request the server to fetch data.

store.peekAll directly returns a DS.RecordArray.
store.peekRecord direclty returns record

It's important to note that DS.RecordArray is not a JavaScript array, it's an object that implements Ember.Enumerable. This is important because, for example, if you want to retrieve records by index, the [] notation will not work--you'll have to use objectAt(index) instead.

From Ember.Enumerable, most of the time I happened to use the following,
forEach to iterate
map to transform to new Array
filterBy findBy for filtering based on single property check
toArray converting to normal native array

Ember Freak
  • 12,918
  • 4
  • 24
  • 54
  • Is this all true for store.query()? The Ember Guides only say it returns a "promise" which I'm not clear what that means. – Cameron Jun 29 '17 at 16:37
  • 1
    yes its true for `store.query` too. I updated with more info. in the guide they mentioned like this `This method returns a DS.PromiseArray in the same way as findAll.` – Ember Freak Jun 29 '17 at 16:56
-3

findAll will return a Promise which will resolve to a RecordArray. The RecordArray is an ArrayProxy.

http://emberjs.com/api/classes/Ember.ArrayProxy.html

This is everything you need.

If you google "ember findall" you will find docs for "Ember.js - Models: Finding Records - Guides" as well.

https://guides.emberjs.com/v2.5.0/models/finding-records/

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
GerDner
  • 399
  • 1
  • 11