Ember.js: Рассчитать сумму свойства всех дочерних моделей.

Мое приложение имеет следующие модели:

App.Store = DS.Store.extend({
    revision: 11,
    adapter: 'DS.FixtureAdapter'
});

App.List = DS.Model.extend({
    name: DS.attr('string'),
    users: DS.hasMany('App.User'),
    tweetsUnread: function(){
        /////////////////////////////////////////
        // Code to dynamically calculate the sum 
        // of tweetsUnread property of all
        // App.User that are related to this list
        /////////////////////////////////////////
    }
});

App.User = DS.Model.extend({
    screenName: DS.attr('string'),
    tweets: DS.hasMany('App.Tweet'),
    tweetsUnread: function(){
        // TODO: check if this is the correct way to do it
        ,return this.get('tweets').get('length');
    }.property('tweets.@each'),
    list: DS.belongsTo('App.List')
});

App.Tweet = DS.Model.extend({
    text: DS.attr('string'),
    user: DS.belongsTo('App.User')
});

Как я могу рассчитать сумму всех App.User.tweetsUnread и заставить его автоматически обновлять App.List.tweetsUnread?

Ответы на вопрос(3)

Ваш ответ на вопрос