# Reloading model when using transitionToRoute approach

**URL:** <https://discuss.emberjs.com/t/reloading-model-when-using-transitiontoroute-approach/2614>\
**Category:** Design\
**Created:** [September 12, 2013, 9:11pm UTC](https://discuss.emberjs.com/t/reloading-model-when-using-transitiontoroute-approach/2614 "2013-09-12T21:11:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![asaf000](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@asaf000](https://discuss.emberjs.com/u/asaf000)\
**Post date:** [September 12, 2013, 9:11pm UTC](https://discuss.emberjs.com/t/reloading-model-when-using-transitiontoroute-approach/2614/1 "2013-09-12T21:11:39Z")

</div>

Hey,

Assuming i’m currently in route ‘foo’, it sometimes make sense to requesting a model re-load for the same transition, but invoking _TransitionToRoute(‘foo’)_ would not re-load the model due to:

> ```
> Note that for routes with dynamic segments, this hook is only
> 
> ```

```
executed when entered via the URL. If the route is entered
through a transition (e.g. when using the `linkTo` Handlebars
helper), then a model context is already provided and this hook
is not called. Routes without dynamic segments will always
execute the model hook.

```

But in situations such as performing some server invocation that changes too many properties in the model, I’d like to reload the model,

Currently I maintain dirty workarounds to achieve that but I’d like to have a better approach,

Does it make sense to extend the transition mechanism to allow model re-load even though the transition context already contains a model? or is there a better approach?

Thanks.

---

<div class="post-metadata">

**Author:** ![gauthamns](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/gauthamns/32/14976_2.png) [@gauthamns](https://discuss.emberjs.com/u/gauthamns)\
**Post date:** [September 13, 2013, 6:16am UTC](https://discuss.emberjs.com/t/reloading-model-when-using-transitiontoroute-approach/2614/2 "2013-09-13T06:16:39Z")

</div>

Is it not simpler to simply use `model.reload()` function to reload the model whenever required?

For transition to different routes where model is provided, I do the following:

```javascript
setupController: (controller, model) ->
    model.reload()
    controller.set('model', model)

```

This will load the model twice when entering the route. (Haven’t yet explored how to handle that.) There must be a better solution.

---

<div class="post-metadata">

**Author:** ![asaf000](https://avatars.discourse-cdn.com/v4/letter/a/8dc957/32.png) [@asaf000](https://discuss.emberjs.com/u/asaf000)\
**Post date:** [September 13, 2013, 10:56am UTC](https://discuss.emberjs.com/t/reloading-model-when-using-transitiontoroute-approach/2614/3 "2013-09-13T10:56:07Z")

</div>

Hey,

I don’t use Ember Data, I need a way to recall the _model_ hook again.

---

<div class="post-metadata">

**Author:** ![amiel](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/amiel/32/15097_2.png) [@amiel](https://discuss.emberjs.com/u/amiel)\
**Post date:** [May 23, 2014, 5:15pm UTC](https://discuss.emberjs.com/t/reloading-model-when-using-transitiontoroute-approach/2614/5 "2014-05-23T17:15:49Z")

</div>

I’m pretty sure that [`afterModel`](http://emberjs.com/api/classes/Ember.Route.html#method_afterModel) should do what you need here:

```auto
afterModel: (model) ->
  model.reload()

```

I’m pretty sure that `afterModel` will run when using `transitionToRoute` (tested with v1.5.1), and if `afterModel` it returns a promise, the transition will wait for the promise to fulfill.

---

<div class="post-metadata">

**Author:** ![robclancy](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/robclancy/32/11146_2.png) [@robclancy](https://discuss.emberjs.com/u/robclancy)\
**Post date:** [July 29, 2015, 4:58pm UTC](https://discuss.emberjs.com/t/reloading-model-when-using-transitiontoroute-approach/2614/6 "2015-07-29T16:58:19Z")

</div>

I have come back to this topic a few times now trying to find a solution for this stuff. I was using `setupController` but that changes some of the nice things `model` gives you like waiting on the page to load.

So my solution from this topic…

```nohighlight
    import Ember from 'ember';
    
    var modelHookRun;
    
    export default Ember.Route.extend({
      beforeModel() {
        modelHookRun = false;
      },
      model(params) {
        modelHookRun = true;
        return this.store.findRecord('topic', params.id, {reload: true});
      },
      afterModel(model) {
        if ( ! modelHookRun) {
          return model.reload();
        }
      },
    });

```

---

<div class="post-metadata">

**Author:** ![gerrit](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/gerrit/32/9140_2.png) [@gerrit](https://discuss.emberjs.com/u/gerrit)\
**Post date:** [August 3, 2015, 2:17pm UTC](https://discuss.emberjs.com/t/reloading-model-when-using-transitiontoroute-approach/2614/7 "2015-08-03T14:17:22Z")

</div>

I think model.fetchByID(params.id) does always a reload.

---

<div class="post-metadata">

**Author:** ![arohr](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@arohr](https://discuss.emberjs.com/u/arohr)\
**Post date:** [August 21, 2016, 12:03pm UTC](https://discuss.emberjs.com/t/reloading-model-when-using-transitiontoroute-approach/2614/8 "2016-08-21T12:03:53Z")

</div>

I had a similar problem. The solution was to pass the the id instead the model to transitionTo() to force the model hook to be called always:

transitionTo(‘my-route’, model);

changed to:

transitionTo(‘my-route’, model.get(‘id’));

see [Route - 4.6 - Ember API Documentation](http://emberjs.com/api/classes/Ember.Route.html#method_model)
