Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4831

Accessing Parent Model from Child Route

$
0
0

@rjoxford wrote:

I have a child route, with a child model, in which I display data about that child model. I also want to be able to display a few other bits of information about the parent model. But this seems to be far more complicated than it ought to be.

The route for the child contains two dynamic segments - //parent/:parent_id/child/:child_id.

The child model is set by the link-to helper in the parent route. This seems the sensible, clean and logical way to set the child model. However, it bypasses the model hook in the route, which is the only place I seem to be able to access the parent model.

Ideally, I’d like to reopen the model in the route, and hash the parent model together with the child model. Alternatively, I’d like to be able to access the parent model from the child controller, in a similar way to modelFor in the route. Either of these would allow me to make use of the dynamic segments in the URL.

The only way I can see to be able to do this is to use query params, and just maintain the parent model throughout. I really don’t want to do this. Frankly, it would be ugly, and would needlessly complicate the design. Any better solutions?

Posts: 5

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 4831

Trending Articles