Ember Model Object hasMany does not return array as I would expect

Viewed 2158

I am trying to use Ember Data's hasMany field to return me an array and get the count of the items in the array as a computed property. However, when I do the following, it returns me an object (which appears to a promise because of the {async: true}?) instead of the array I expected.

App.Shift = DS.Model.extend({
  name: DS.attr('string'),
  people: DS.hasMany('person', {async: true});
  number_of_people: (function(){
    this.get('people').length
  }).property('people')
)};

App.Person = DS.Model.extend({
  first_name: DS.attr('string'),
  last_name: DS.attr('string')
});

Update: I would like to return the length of people. I tried this but when I access the property I get the promise object returned still instead of the value of completed promise in the then. How would I get the value of the evaluated promised to be returned?

number_of_people: (function(){
  return this.get('people').then(function(people){
    return people.get('length');
  });
})
1 Answers
Related