0

I am trying to use Ember.computed.sort and can't figure out how to sort by the name of a belongTo property. I have been on GOogle for hours and can't find the right combination. help please!

// my model
export default DS.Model.extend({
        targetName: DS.attr(),
        targetType: DS.attr(),
        rack: DS.belongsTo('rack', {async: true}),
});

// this works:
export default Ember.Controller.extend({
    sortedTargets: Ember.computed.sort('model', 'sortDefinition'),
    sortDefinition: ['targetType']
});

// this doesn't work :
export default Ember.Controller.extend({
    sortedTargets: Ember.computed.sort('model', 'sortDefinition'),
    sortDefinition: ['rack.name']
});
Liam
  • 27,717
  • 28
  • 128
  • 190
Rick
  • 21
  • 1

1 Answers1

2

thanks @Lux comments on this thread. here is a solution that worked for me. Note the Ember.computed.alias on the model.

export default DS.Model.extend({
    targetName: DS.attr(),
    targetType: DS.attr(),
    rack: DS.belongsTo('rack', {async: true}),
    rackName: Ember.computed.alias('rack.name'),
});

// this works:
export default Ember.Controller.extend({
    sortedTargets: Ember.computed.sort('model', 'sortDefinition'),
    sortDefinition: ['targetType']
});

// this works too :) :
export default Ember.Controller.extend({
    sortedTargets: Ember.computed.sort('model', 'sortDefinition'),
    sortDefinition: ['rackName']
});
Rick
  • 21
  • 1