fischer
fischer

Reputation: 269

EmberJS - Computed property referencing firstObject do not update

I have a model like this:

App.Conversation = DS.Model.extend({
    body             : DS.attr('string'),
    created_at       : DS.attr('date'),
    entry            : DS.hasMany('Entry', {async: true}),
    user             : DS.belongsTo('User'),
    allEntriesLoaded : DS.attr('boolean'),
    entryProxyBody   : function() {
        return this.get('entry.firstObject.body');
    }.property('entry.firstObject.body')
});

As you can see it references its Entry hasMany relationsship in the function entryProxyBody. This reference works great, as calling entryProxyBody do indeed return the body-attribute from the first object in Entry.

However my problem is, that the computed property is not updated, when a new value is added to the Entry-store.

I add a new record like this:

App.NewController = Em.ObjectController.extend({
    actions: {
        save: function() {

            var entry = this.store.createRecord('entry', {body: 'Test', created_at: new Date() });

            this.store.find('conversation', this.parentController.get('id')).then(function(conversation) {

                conversation.get('entry').pushObject(entry);
                entry.save();
            });

        }
    },
});

However.. If I update the first object in Entry directly using Ember Inspector in Chrome, then the computed property changes as it should.

What am I missing? Thank you for your help!

Upvotes: 0

Views: 430

Answers (1)

Richard A
Richard A

Reputation: 2100

I think you might want to observe for changes for each entry in the entry array.

entryProxyBody:function() {
    return this.get('entry.firstObject.body');
}.property('[email protected]')

Upvotes: 0

Related Questions