There was a similar issue already.
Assuming the following routes:
App.Router.map(function (match) {
match('/').to('index');
match('/posts').to('posts', function (match) {
match('/').to('postsIndex');
match('/:post_id').to('post', function (match) {
match('/comments').to('comments', function (match) {
match('/').to('commentsIndex');
match('/:comment_id').to('showComment');
});
});
});
});
Is it possible to access both post_id
and comment_id
in ShowCommentRoute
? Otherwise should I forget about composite keys in my models?
Why CommentsRoute#model(params)
and CommentsIndexRoute
argument is always empty? How to retrieve Post
's comments when?
My fiddle.
Run this example too (there are console log showing the problem.
UPDATE after some investigation:
Only PostRoute
will have params.post_id
.
Only ShowCommentRoute
will have params.comment_id
and will not have params.post_id
.
This is unacceptable for applications where models have composite keys. In case when we are transitioning to showComment
step by step, we can obtain Comment
instance:
App.ShowCommentRoute = Ember.Route.extend({
model: function(params) {
var post_id = this.controllerFor('post').get('content.id');
return App.Comment.find(post_id, params.comment_id);
}
});
But this won't work if we directly visiting /posts/1/comments/1
. In this case this.controllerFor('post')
always undefined
.
*IndexRoute
(PostRoute
and PostInderRoute
in this example)Using ember-1.0.0-rc.1 it is now possible to access the parent route's model when directly visiting a url.
App.ShowCommentRoute = Ember.Route.extend({
model: function(params) {
var post = this.modelFor('post');
return App.Comment.find(post.get('id'), params.comment_id);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With