How to find all entries of more than one type of record in Ember.js?

Thursday, July 10, 2014

I have two types of records in the Ember DS.Store: users and location. (In fact I have more, but for the sake of simplicity).


Now to get all entries of, say, 'user', I would simply do



this.store.find('user')


Now say I have a variable allResults and I assign it to this command.



allResults = this.store.find('user')


This gives me what Ember calls a promiseArray, and to do anything after this promise array loads I simply



allResults.then(successfunction(), failurefunction())


Now this works great when I need only one type of record - say I need only users, I can easily call my successfunction() as the first argument.


However, my need goes beyond that: I am basically building a searchbar that searches through these records, so if someone types in "mary", it needs to both show the user "Mary" and the location "mary Ave" for example.)


So I need the combined results of



this.store.find('user')


&



this.store.find('location')


Therefore, here are my questions: [I feel that either of them would work.]




  1. Is there a way I can fetch all data pertaining to both 'user' and 'location' and have it returned as one glorious promiseArray? This seems likely and also the best way of approaching this issue.




  2. Can you concatenate two promiseArrays to make one larger one, then user the .then function for the larger one? If so, how?









http://ift.tt/1nhVMjQ