Share a few things here.
Save cache
this.store.all('foo').clear();
just breaks the internal filter all until the foo record is changed / added / deleted, causing the filter to be recounted for writing to the repository. I say this to show that clear does not delete records from the ED repository.
Example (click the button, look at the console, read the funny action code)
http://emberjs.jsbin.com/OxIDiVU/103/edit
At the same time, the ajax is not cached, it is a property / relation to the record instance that is cached (and the record).
The correct way to delete records from the repository is store.unloadAll('foo')
Promiselandia
I know that you are already familiar with promises, so this part may be useless, but itโs worth documenting
Asynchronous relationships are really cool because they return PromiseObject / PromiseArray for belongsTo / hasMany . PromiseObject / PromiseArray extends ObjectProxy / ArrayProxy (these are the same things as ObjectController / ArrayController ). This essentially enables PromiseObject / PromiseArray ability of the proxy to get / set the model properties under it. In this case, the installation / receipt occurs according to the promise, โdoes not workโ until the promise is resolved (it does not work, just return undefined). * Caution, methods do not exist by promise, so you cannot name a saved promise and expect it to work.
Ex. using your models.
var foo = this.store.find('foo', 1); var bar = foo.get('bar');
later, the bar resolved, the bar is still a PromiseObject
bar.get('name');
foo will continue to return a PromiseObject
var bar2 = foo.get('bar');
preservation
bar.save(); // Boom no workey bar.then(function(realBar){ realBar.save(); // workey });
In your case, I have 3 recommendations
Create your own promise, decide when you want, use Ember.RSVP.all in the necessary entries (given that they may or may not be allowed, therefore, async)
var self = this; var promise = new Ember.RSVP.Promise(function(resolve, reject){ self.store.find('foo').then(function(foos) { Em.RSVP.all(foos.getEach('bar')).then(function(bars){ var filtered = bars.filterBy('name', 'bazz'); resolve(filtered); }); }); }); return promise;
http://emberjs.jsbin.com/OxIDiVU/104/edit
asynchronous properties
Many times with asynchronous objects / properties that were not allowed during the model hook (which blocks on promises and wait for their resolution), a good trick is to set a placeholder, etc.
var items = []; controller.set('model', items); // promise from above promise.then(function(records){ items.pushObjects(records.toArray()); // toArray may or may not apply });
http://emberjs.jsbin.com/OxIDiVU/106/edit