# Model isn't updating when I use a query

**URL:** <https://discuss.emberjs.com/t/model-isnt-updating-when-i-use-a-query/4484>\
**Category:** Ember Data\
**Created:** [March 13, 2014, 6:29pm UTC](https://discuss.emberjs.com/t/model-isnt-updating-when-i-use-a-query/4484 "2014-03-13T18:29:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gravyfries](https://avatars.discourse-cdn.com/v4/letter/g/858c86/32.png) [@gravyfries](https://discuss.emberjs.com/u/gravyfries)\
**Post date:** [March 13, 2014, 6:29pm UTC](https://discuss.emberjs.com/t/model-isnt-updating-when-i-use-a-query/4484/1 "2014-03-13T18:29:05Z")

</div>

The model automatically updates if I use:

```
ST.FiltersSymbolsRoute = Ember.Route.extend({
  model: function() {
  return this.store.find('filter');
  }
});

```

But when I introduce a query, the model does not automatically update:

```
ST.FiltersSymbolsRoute = Ember.Route.extend({
  model: function() {
  return this.store.find('filter', {isSymbol: true});
  }
});

```

Here’s the fiddle: [http://jsbin.com/yeyiroyo/1/](http://jsbin.com/yeyiroyo/1/)

To replicate the bug, click Symbols, click “+”, type something, and hit enter You’ll notice that nothing happens, but if you click Users, then Symbols again – you’ll notice that the model has updated. How can we make it update immediately?

---

<div class="post-metadata">

**Author:** ![stefan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/stefan/32/14174_2.png) [@stefan](https://discuss.emberjs.com/u/stefan)\
**Post date:** [March 13, 2014, 8:22pm UTC](https://discuss.emberjs.com/t/model-isnt-updating-when-i-use-a-query/4484/2 "2014-03-13T20:22:03Z")

</div>

Stackoverflow would be the best venue of when asking for help. Please reopen, and cross link. I’ll gladly look at your question then.

---

<div class="post-metadata">

**Author:** ![machty](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/machty/32/13933_2.png) [@machty](https://discuss.emberjs.com/u/machty)\
**Post date:** [March 13, 2014, 8:28pm UTC](https://discuss.emberjs.com/t/model-isnt-updating-when-i-use-a-query/4484/3 "2014-03-13T20:28:19Z")

</div>

The problem is that a query find is deferring to the server to return an array of records based on that query. There’s no way to have pre-existing query record arrays to automatically update from the server just from a `.save()` call alone; that would imply the server knowing to somehow know about all the existing query record arrays in place and re run that original query logic, send it back, and Ember would somehow know to manually update that record array. So as far as I know, query-based record arrays are kinda one-shot. I’m not the Ember Data pro so I’m not sure the most idiomatic way to go from here; maybe refiring the model hook in some way? (When the `query-params-new` feature flag is enabled, it adds a new method to `Ember.Route` called `refresh` which will refire the model hooks on that route and do an “in-place” transition, which you could try.)

---

<div class="post-metadata">

**Author:** ![gravyfries](https://avatars.discourse-cdn.com/v4/letter/g/858c86/32.png) [@gravyfries](https://discuss.emberjs.com/u/gravyfries)\
**Post date:** [March 13, 2014, 8:31pm UTC](https://discuss.emberjs.com/t/model-isnt-updating-when-i-use-a-query/4484/4 "2014-03-13T20:31:07Z")

</div>

That’s kind of what I was thinking too, haven’t had any luck with the ‘refresh’ method yet.

---

<div class="post-metadata">

**Author:** ![gravyfries](https://avatars.discourse-cdn.com/v4/letter/g/858c86/32.png) [@gravyfries](https://discuss.emberjs.com/u/gravyfries)\
**Post date:** [March 13, 2014, 8:33pm UTC](https://discuss.emberjs.com/t/model-isnt-updating-when-i-use-a-query/4484/5 "2014-03-13T20:33:59Z")

</div>

Thanks stefan:

> <https://stackoverflow.com/questions/22390185/model-isn-t-updating-when-i-use-a-query>

---

<div class="post-metadata">

**Author:** ![gravyfries](https://avatars.discourse-cdn.com/v4/letter/g/858c86/32.png) [@gravyfries](https://discuss.emberjs.com/u/gravyfries)\
**Post date:** [March 13, 2014, 9:24pm UTC](https://discuss.emberjs.com/t/model-isnt-updating-when-i-use-a-query/4484/6 "2014-03-13T21:24:43Z")

</div>

update: this fixed it:

```
ST.FiltersSymbolsRoute = Ember.Route.extend({
model: function() {
   return this.store.filter('filter', function(record) {
      return record.get('isSymbol') === true;
   });
}
});

```

---

<div class="post-metadata">

**Author:** ![balint](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/balint/32/12521_2.png) [@balint](https://discuss.emberjs.com/u/balint)\
**Post date:** [March 14, 2014, 7:24am UTC](https://discuss.emberjs.com/t/model-isnt-updating-when-i-use-a-query/4484/7 "2014-03-14T07:24:09Z")

</div>

More concisely, you can write:

```nohighlight
model: function() {
  return this.store.find('filter').findBy('isSymbol');
}

```

---

<div class="post-metadata">

**Author:** ![alexspeller](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/alexspeller/32/14812_2.png) [@alexspeller](https://discuss.emberjs.com/u/alexspeller)\
**Post date:** [March 28, 2014, 8:27pm UTC](https://discuss.emberjs.com/t/model-isnt-updating-when-i-use-a-query/4484/8 "2014-03-28T20:27:44Z")

</div>

For future reference @balint’s solution is not the same thing and will not live update in the same way that @gravyfries solution will.

---

<div class="post-metadata">

**Author:** ![balint](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/balint/32/12521_2.png) [@balint](https://discuss.emberjs.com/u/balint)\
**Post date:** [March 28, 2014, 8:42pm UTC](https://discuss.emberjs.com/t/model-isnt-updating-when-i-use-a-query/4484/9 "2014-03-28T20:42:23Z")

</div>

@alexspeller is right, sorry about that. I’d probably overlooked the use of `this.store.filter` in the original example.
