The Solution

First take a look at the link above to see how it is possible to filter the owners by the name of their pets. This is a very basic working illustration of the principle, but follows the approach set out from this Github Issue.

The interesting part of the code is the filteredOwners computed property

First, we must ensure the first parameter passed into the RSVP.filter is an array, see this Github Issue for more details on why this is necessary.

let ownersArray = this.get(‘model’).toArray();

Then we loop through the ownersArray to find any pets with matching names—using the then() approach explained earlier to ensure that the promises have resolved. As the body function of RSVP.filter respects promises we can use this feature to asynchronously get the pets.

RSVP.filter returns a promise that will become fulfilled with the result of running filterFn on the values the promises become fulfilled with.

let filterPromise = Ember.RSVP.filter(ownersArray, owner => {

return owner.get(‘pets’).then( pets => {

return pets.isAny(‘name’, petName);

});

});

Finally, the promise should resolve to an array of items so we create a DS.PromiseArray to do this.

When the promise is resolved the resulting value will be set to the PromiseArray’s content property. This makes it easy to create data bindings with the PromiseArray that will be updated when the promise resolves.

return DS.PromiseArray.create({

promise: filterPromise

});

In this example each individual step is separated to present them as clearly as possible, but it could be written more concisely as…

An additional benefit of this approach is that filteredOwners now has bindable attributes which track the promises life cycle and can be used in the template e.g.