dimanche 10 juillet 2016

Ember.js dynamic model requests

I am trying to make a request from the store for a model based on the result of a previous model request. Please find the code below:

For the route:

model(params) {
var id = params.framework_id;
var main = this;
  return Ember.RSVP.hash({
    question: this.store.query('question', {orderBy: 'framework', equalTo: id}),
    framework: this.store.find('frameworks', id),
    frameworks: this.store.findAll('frameworks')
  })
}

Then in the route there is a setupController:

setupController: function(controller, model) {
this._super(controller, model);
var main = this;
...
controller.set("frameworkName", model.framework.get('name'));

var includedFramework = model.framework.get('includedFramework');
var includedFrameworkModel = this.store.find('frameworks', includedFramework);

Ember.Logger.info(model.framework)
Ember.Logger.info(includedFrameworkModel);

if (model.framework.get('includedFramework') != undefined) {
  var linked = main.store.find("frameworks", model.framework.get('includedFramework'));
  controller.set("linkedFramework", {id: linked.get('id'), name: linked.get('name')});
}
}

In the controller setup, using model.framework.get('name') works without a problem. mode.framework.get('includedFramework') works fine and returns an ID to another framework that is stored in the framework model. I then intend to pull the "included framework" in the store with another store.find request. Unfortunately this second store.find doesn't not return the model record in the same way as the first. Here is an inspector view of what each request returns:

model.framework -

model.framework

includedFrameworkModel -

includedFrameworkModel

Any help is greatly appreciated!

Aucun commentaire:

Enregistrer un commentaire