Model inheritance for Ember.js routes
Update 2014-04-01
As of Ember.js 1.5.0 this feature is enabled by default for release builds.Update 2014-02-10
As of commit b351b4a7c41dbaa5d4b1c5508f02df6b957018c7 this feature is enabled by default. This includes Canary builds.
I’ve just helped push a feature to Ember.js’ master that might help you shave off a couple of lines of code. By switching on the ember-routing-inherits-parent-model
feature flag your routes will inherit the model from the parent resource by default.
At the moment resources won’t inherit the model from their parents, but that might change in the future, depending on how appropriate the core team deems it.
Getting the right Ember.js #
You will have to grab the build from the Canary page. You can read more about the different build channels in the Getting Started section of the guides.
Enabling the feature #
First you should read through the section on the guides about enabling feature flags to get an idea of how they work, and you can also check FEATURES.md for which features are currently available.
As mentioned before, the flag to enable model inheritance for routes is ember-routing-inherits-parent-model
. I have prepared a simple example jsbin demonstrating how it works: http://jsbin.com/eXacuQaj/12/edit?html,js,output
If you click “Go to edit releases” you will see the model information displayed, and you can even pop Ember Inspector open and check that the model for the route is indeed the same as the releases resource.