Reputation: 1
I am trying to access a related(belongsTo) model from the parent model. In a component I am receiving this top level employee model and there I am trying to access address model as below.
this.get('employee').get('address')
but the address object I received is not of Model type, so I am not able to call any Model function on it. Surprisingly this.get('employee')
returns a model object and i am able to call any Model function using it.
Complete Employee model is as below
export default DS.Model.extend({
serialNo: DS.attr('string'),
name: DS.attr('string'),
address: DS.belongsTo('employee/address')
});
and the address model is
export default DS.Model.extend({
addressId: DS.attr('string'),
streetNo: DS.attr('string'),
city: DS.attr('string'),
});
Upvotes: 0
Views: 113
Reputation: 1057
it would be better if you share complete file of both models Employee and Address models.
employee= DS.Model.extend({
serialNo: DS.attr('number'),
name: DS.attr('number'),
address: DS.belongsTo('address', { inverse: 'employee' }) ,
});
Address model should be something like that
address= DS.Model.extend({
employee: DS.belongsTo('employee', { inverse: 'address' }) ,
});
Upvotes: 0