Thank you, Skaterdav, for that link. Shows interesting things I seem to have missed. Anyways, could you explain how that helps me with my problem?
Sure, having all data pre-fetched would work, but I don’t need any new API for that. I could just specify the relationships as { async: false } and fetch all required records before. If that is the only way to achive this, okay, but I thought it might work with the async way, too?
So if I understand correctly, you want to sort items by details.name but all the data might not be in the store so you would need to fetch it if it isn’t already loaded?
Yes. Well, I think I’m looking for a way to get notified when all async relationships have been loaded so that I can sort.
Maybe there is a good way to grab all the Promises and put it into an Ember.RSVP.all?
Something like…
(not tested)
// app/models/a.js
import DS from 'ember-data';
const { hasMany } = DS;
export default DS.Model.extend({
items: hasMany('b', { async: true }),
setSortedItems: Ember.observer('items', function() {
let relationshipPromises = this.get('items').map(item => item.get('details.name')); // item.get('details.name')) should return a Promise, right?
Ember.RSVP.Promise.all(relationshipPromises).then(function() {
// at this point, shouldn't it be possible to sort the array?
})
})
});