How can one do processing on an ember model before returning it in the hook? I currently have something along the following lines in a route
model: function (params) {
var list_of_things = [];
this.store.find('thing').then(function (things) {
things.forEach ( function (thing) {
thing.get('relatedThing').then(function(relatedThing) {
if (relatedThing.get('id') == params.relatedThing_id) {
list_of_things.push(thing)
}
})
})
});
return list_of_things;
}
I'm essentially creating an array of models but filtering them first. Really what I want to do is just filter the array of models, but I couldn't figure out another way to do it as relatedThing is a foreign model (thing belongsTo relatedThing). Ideally what I'm trying to do is something like:
return this.store.find('thing', where thing.relatedThing.id = someValue)
The problem is, of course, that because of promises and such, only an empty list_of_things is returned and the model comes up empty.
I assume I have to somehow structure this to return a promise from the model hook, but I'm not quite sure how.
Aucun commentaire:
Enregistrer un commentaire