0
votes

I have a model that has a one to many relationship with multiple translations:

App.Category = DS.Model.extend({
    translation_ids: DS.hasMany('translation', { embedded: 'always' }),
});

App.Translation = DS.Model.extend({
    name: DS.attr(),
    locale: DS.attr()
});

I want to fetch the name of the category according to the selected language :

App.CategoryController = Ember.ObjectController.extend({   
    needs: ['settings'],
    currentLocale: Ember.computed.alias('controllers.settings.currentLocale'),
    name: function() {
        var translations = this.get('translation_ids').filterBy('locale', this.get('currentLocale'));
        Ember.assert("Only one translation is expected", translations.length === 1);
        return translations[0].get('name');
    }.property('translation_ids') 
});

Everything works out great. But when I edit my category, the "name" property doesn't update : enter image description here

I have tried a million different things, but nothing work so far. Could someone point out my mistake?

1

1 Answers

1
votes

translation_ids is an array, so you want to observe the elements in the array, not just the array itself. Use .property('translation_ids.@each').