# afterModel hook triggers two identical requests

**URL:** <https://discuss.emberjs.com/t/aftermodel-hook-triggers-two-identical-requests/4843>\
**Category:** Uncategorized\
**Created:** [April 11, 2014, 8:57am UTC](https://discuss.emberjs.com/t/aftermodel-hook-triggers-two-identical-requests/4843 "2014-04-11T08:57:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fed03](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/fed03/32/15688_2.png) [@Fed03](https://discuss.emberjs.com/u/Fed03)\
**Post date:** [April 11, 2014, 8:57am UTC](https://discuss.emberjs.com/t/aftermodel-hook-triggers-two-identical-requests/4843/1 "2014-04-11T08:57:19Z")

</div>

Hi all  
In my app I need that when I visit the root, it redirects to the view of the most recent model that in this case is always the firstObject in the collection.

```auto
App.Router.map(function() {
    this.resource('threads', { path: '/' }, function() {
        this.route('view', { path: ':thread_id' });
    });
});

App.ThreadsRoute = Ember.Route.extend({
  model: function() {
    // console.log('in model);
    return this.store.find('thread');
  },
  afterModel: function(threads) {
    // console.log('in afterModel);
    this.transitionTo('threads.view', threads.get('firstObject'));
  }
});

```

This is working without problems, but wheter I directly go to the root url or to the view url, 2 identical requests to `/threads` are made. With the help of `console.log()` we can see that model and afterModel are both triggered 2 times. As soon I comment the afterModel section the redirection obviously doesn’t work anymore but the requests are back to 1.

Moreover according to [this Changelog](http://emberjs.com/blog/2014/03/30/ember-1-5-0-and-ember-1-6-beta-released.html#toc_routes-inherit-model) and the doc about [transitionTo](http://emberjs.com/guides/routing/redirection/) the child model hook should never be triggered, shouldn’t it?

Any help is gladly accepted!

---

<div class="post-metadata">

**Author:** ![splattne](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/splattne/32/3694_2.png) [@splattne](https://discuss.emberjs.com/u/splattne)\
**Post date:** [April 11, 2014, 9:08am UTC](https://discuss.emberjs.com/t/aftermodel-hook-triggers-two-identical-requests/4843/2 "2014-04-11T09:08:16Z")

</div>

Since Threads/View are nested routes, the `ThreadsRoute` will be also called on the `View` route.

I think you should just call the ThreadsRoute → ThreadsIndexRoute or separate model and afterModel hooks this way:

```
App.ThreadsRoute = Ember.Route.extend({
  model: function() {
    // console.log('in model);
    return this.store.find('thread');
  }
});

App.ThreadsIndexRoute = Ember.Route.extend({
  afterModel: function(threads) {
   // console.log('in afterModel);
    this.transitionTo('threads.view', threads.get('firstObject'));
  }
});

```

---

<div class="post-metadata">

**Author:** ![Fed03](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/fed03/32/15688_2.png) [@Fed03](https://discuss.emberjs.com/u/Fed03)\
**Post date:** [April 11, 2014, 9:43am UTC](https://discuss.emberjs.com/t/aftermodel-hook-triggers-two-identical-requests/4843/3 "2014-04-11T09:43:22Z")

</div>

That’s worked perfectly! You’re my hero, I knew I was doing something wrong but very stupid XD
