If you wanted the Edit route’s model to be the Thing loaded in the Thing route, you have to define a model hook on the Edit route to call this.modelFor('thing'), which is pretty repetitive and cumbersome.
Proposal
For this.route() routes that don’t specify a model hook, the model for that route should default to the parent resource’s model.
This should be totally backwards compatible unless someone is doing something extremely strange.
When I first started using Ember, I just “assumed” that a route inherited its model from its parent resource because it just made sense. Wishful thinking.
Due to overwhelming negativity, we’re not going to be implementing this feature.
Just kidding.
There’s one risky corner case to consider regarding backwards compatibility, but I think we’re probably fine.
Basically, presently, if you have a model-less route and haven’t specified a controller for that route, a default empty Ember.Controller will be generated for you to drive the template. Now, that model-less route will inherit the model from a parent, which means the generated controller might now be an Ember.ObjectController or Ember.ArrayController wrapping the model of a parent object. Now, 99.99% of the time this should be fine, but as @alexspeller pointed out, it’s possible that problems might be caused if you’re generating/writing properties entirely within the template, like
{{input value=foo}}
foo is {{foo}}
If foo didn’t exist on the controller, it would create that property. In the case of a Object/Array controller, it would proxy the read/write of foo through to the underlying model.
I think this is mega rare and probably nothing to worry about, but I’d like to get a sense of what other kinds of gotchas might happen by suddenly having routes/controllers inherit their parent models. Help me brainstorm?
How does this work with a route’s index view? Being new to Ember, I don’t know all the details so maybe I’m doing this wrong in the first place. Basically, I’ve defined a model for the “main” route but am trying to use it within the index template but it’s unavailable. Would this feature fix that issue?
@Panman8201 yes this will fix exactly that. Note that it just merged into Canary and will be on Beta tomorrow (or over the weekend); just keep that in mind in case you’re expecting it to work right away.
Great! I was trying to use it in the Canary build (because I’m also using the new queryParams functionality) but it wasn’t seem to be working. I’ll take another, closer look later today to see if everything made it in. Thanks