aquavitae
aquavitae

Reputation: 19154

Unexpected text being rendered by Ember

I have models

// models/group
export default DS.Model.extend({
    parent: DS.belongsTo('parent'),
    items: DS.hasMany('item', {async: true}),

    quantity: Ember.computed.sum('[email protected]'),

});

// models/item
export default DS.Model.extend({
    ...
    quantity: DS.attr('number')
});

And in my template (with controller.model set to parent) I try to render

{{#each group}}
    {{quantity}}
{{/each}}

and expect a list of numbers, but instead what's rendered is a list of text like <spa@model:item::ember1036:165>

I'm guessing that the async promise is only resolved after rendering, but then why does it not update?

Upvotes: 1

Views: 26

Answers (1)

Kingpin2k
Kingpin2k

Reputation: 47367

I don't believe sum will pull properties from each item in a collection. I believe it has to be a collection of numbers.

quantities: function(){
   return this.get('items').getEach('quantity');
}.property('[email protected]'),

quantity: Ember.computed.sum('quantities'),

Upvotes: 2

Related Questions