vendredi 5 juin 2015

Computer Property not updating on hasMany

I have a pretty simple model:

//models/build
import DS from 'ember-data';

export default DS.Model.extend({
    shipments: DS.hasMany('shipment')
});

I need to update a computer property whenever a new shipment is added or removed, so I'm using my controller, like this:

//controllers/build
import Ember from 'ember';
export default Ember.Controller.extend({
    init: function() {
        this.get('allShips');
        this.get('ships');
    },
    allShips: Ember.computed.alias('model.ships'),
    ships: function() {
        console.log('updating ships');
    }.property('model.@each.shipments')
});

I'm not consuming the computer properties in my template anywhere, I just need to keep them updated to do some computational work so I'm just getting them in the init function. I'm getting "updating ships" in the console when I'm entering the build route correctly, but after that it won't update no matter how many shipments I add or remove.

I've tried many different properties, model.ships.@each, allShips, @each.allShips, allShips.@each, and dozens of all combinations, but all were in vain. I've never had this kind of trouble with computer properties so any advice would be appreciated.




Aucun commentaire:

Enregistrer un commentaire