Search code examples
ember.jsember-dataember-cli

ember model array and computed properties


Say I have the following:

export default DS.Model.extend({

    analyses: DS.hasMany('analysis', { async: true }),

    requiresAuth: Ember.computed.equal('analyses.@each.requiresAuth', true),

    isAdjusted: Ember.computed.equal('analyses.@each.isAdjusted', true)

});

The idea is that I can query the top level model to see if any of the child analysis models have isAdjusted or requiresAuth

it's not working - hence the question - am I asking too much of ember data + computed?


Solution

  • I don't think you can use that dependent key syntax for Ember.computed.X macros, so the current code you have doesn't do what you're expecting.

    I suggest doing the logic yourself like this:

    Ember.computed('analyses.@each.requiresAuth', function() {
      return this.get('analyses').any(item => item.get('requiresAuth'));
    });