Last active
December 12, 2015 01:48
-
-
Save joeytrapp/4693660 to your computer and use it in GitHub Desktop.
How to get parent route models in the child route model() method.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.Router.map(function() { | |
this.resource('posts', function() { | |
this.resource('post', { path: '/:post_id' }, function() { | |
this.resource('permissions', function() { ... }); | |
}); | |
}); | |
}); | |
App.PermissionsRoute = Ember.Route.extend({ | |
model: function() { | |
// need parent route model | |
return App.Permission.find({ post_id: parent.model.id }); | |
} | |
}); | |
// Currently I access the parent routes controller for its model like: | |
App.PermissionsRoute = Ember.Route.extend({ | |
model: function() { | |
var post = this.controllerFor('post').get('model'); | |
return App.Permission.find({ post_id: post.get('id') }); | |
} | |
}); | |
// But, this doesn't work when the permissions route is entered via url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment