Nested routes don't appear to update model


#1

I have a nested route which doesn’t seem to want to update when I save a new record to the model.

If I visit my colleagues/colleague/{id}/vacation route I get a list of models which is correct. To add a vacation, the users clicks a button that does a transitionTo in the controller to the colleague’s/colleague/{id}/vacation/request route. This route contains the form and validation logic for a new vacation and is an {{outlet}} of the parent path.

Where things get weird is I can pass validation, save the record to the model, verify its presence on the backend (i.e. it saved successfully) but it doesn’t update the current list.

Even if I trigger a transitionTo to go back to the parent route after a successful save the route doesn’t refresh so the model doesn’t update.

However, if I refresh the browser manually, this performs a fetch (GET) from the backend and the added vacation is there!

What am I missing or have I misunderstood nested routes/outlets?


#2

Hey @GrandSlam90,

What store method are you using in the model hook of the colleagues/colleague/:id/vacation route? Because that is a parent route I wouldn’t expect it to refresh it’s model (though I think there may be ways you can force it to). If a transition occurs “within” a parent route, like in your case, the parent route model will not refresh AFAIK. My hunch is that if you went to a completely different route and then went back to the c/c/id/vacation route it would do a refetch.

Anyway, the reason for my first question is that your model should still update IF you used peekAll or findAll. I’m assuming you’re doing sometihing like createRecord followed by a save, which should live update any record arrays that result from findAll/peekAll. Unfortunately AFAIK store.query does NOT return a live record array, so if you’re using store.query in the vacation route model, you will not get additional records in the array even though they are already present in your front end store. It’s a real pain.

If you are using query the general recommendation seems to be “use a query to load everything into the store, but then use peekAll in the actual model hook and then filter it down to what you need in the controller”. Not a great solution IMHO but it’s what we’ve got.

For further reading:

https://github.com/emberjs/ember.js/issues/15256 (^ this one was opened by me and got hijacked into a different topic so no real answers)