Search code examples
ember.jsmodelember-data

Ember.js: compute a nested relationship as a model property


I currently have three models, Model, Manufacturer, and Device: A Model belongs to a Manufacturer, and a Device belongs to a Model. However, when I list the devices, I'd also like an entry for the manufacturer. I know I can fetch it easily with model.model.manufacturer.name, however, I'd like Device to have it's own manufacturer property. I have looked into Ember's computed properties, however, I can't seem to find a way to compute the model's manufacturer as the device's property, e.g.:

manufacturer: Ember.computed('manufacturer', function () {
  return this.belongsTo('model').manufacturer
})

That's what I'm aiming for, but it doesn't work. Is this even possible at all?

Thank you!


Solution

  • You need to define like this :

    manufacturer: Ember.computed.alias('model.manufacturer')
    

    and if you don't want to set manufacturer in Device model, so use oneWay instead alias