Set a different controller's model via action doing a fetch query

90 views Asked by At

I am trying to set the content of an another controller but my model returns undefined. I've tried everything I could think of to get the queried results prior to trying to set the other controller's model.

Mapmaker.CategoriesController = Ember.ArrayController.extend({
needs: ['filters'],
actions: {
    setCategories: function(item) {
        var content = this.getFilters(item.id);
        console.log(content.fulfillmentValue._data.objects);
        this.get("controllers.filters").set('model', content.fulfillmentValue._data.objects);
    }
},
getFilters: function(id){
    //trying to force sync
    return Mapmaker.Tile.fetch('?categories=' + id);
}

});

Any thoughts? let me know if I need to show more code. I am using ember-model's restful adapter to query the results.

I am getting results but they are just isLoaded:false the second I try to set the controller's model.

1

There are 1 answers

0
Kingpin2k On

fetch in ember model returns a promise, not a model, use the promise

    var promise = this.getFilters(item.id);
    promise.then(function(content){
      console.log(content);
      this.get("controllers.filters").set('model', content);
    }