1
votes

I've got a base route which loads all categories as the model like this:

import Ember from 'ember';
export default Ember.Route.extend({
  // retrieve all categories as they are needed in several places
  model: function() {
    return this.store.findAll('category');
  }
})

Then there's a sidebar (base.sidebar) which is supposed to use the model from base. The controller looks like this:

import Ember from 'ember';
export default Ember.Controller.extend({
  needs: ['base'],
  categories: Ember.computed.alias('controllers.base.model'),
});

However this doesn't work anymore as of Ember 2.0. categories is just empty.

Which deprecation did I miss?

1
If base.sidebar is a nested route of base and you did not define a model hook for base.sidebar route, then you should be able to get parent model from sidebar controller via this.model. I don't know if it is documented somewhere, I found it by accident. - Gennady Dogaev
Thanks, I didn't know about it either. There is one drawback to this method though. If one day I'll decide to pass sidebar its own model it won't work anymore so I prefer GJK's answer. - Hedge

1 Answers

2
votes

The controller.needs property was deprecated in 1.13 and removed in 2.0. You can read this guide to see how to replace the functionality. For you it'll look something like this:

export default Ember.Controller.extend({
    base: Ember.inject.controller(),
    categories: Ember.computed.alias('base.model')
});