vendredi 28 avril 2017

How to lookup child elements in ember model?

Here are the two models that i have defined

//Plugin model
import DS from 'ember-data';

export default DS.Model.extend({
  name:    DS.attr('string'),
  account: DS.hasMany('account')
});

//account model
import DS from 'ember-data';

export default DS.Model.extend({
  username: DS.attr('string'),
  plugin  : DS.attr('plugin')
});


// Plugin Route
import Ember from 'ember';

export default Ember.Route.extend({
  model: function(){
    return this.store.findAll('plugin');
  }
});


//Accounts route
import Ember from 'ember';

export default Ember.Route.extend({
  model: function(params){
    return this.store.findRecord('account',params.id);
  }
});

The api structure to list accounts associated with a plugin is /plugins/:id/accounts.The problem is i am unable to make request to the same using above code. params.id in case above is id for plugin and not account. Is there something i am missing out on emberjs or should i change my api to bring accounts to root ?




Aucun commentaire:

Enregistrer un commentaire