Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>The problem is that EVERY TIME when I click on Get another random thing and new thing is displayed and I go to recipes route this newly displayed random thing is added to the collection...</p> </blockquote> <p>This is expected behavior. <code>App.Thing.find()</code> does not simply query the api and return results. Instead find() returns an array containing of all Things ember knows about. It includes objects returned by past calls to find(), objects created client-side via App.Thing.createRecord(), and of course individual objects queried via <code>App.Thing.find('random')</code>. After returning this array, find() and kicks off another API call and if that returns additional records they are pushed onto the array.</p> <blockquote> <p>What is wrong here?</p> </blockquote> <p>It does not sound like anything is wrong per-se. If you want to prevent random things from showing up in the ThingsRoute, you'll need to change that route's model to be a filter instead of just returning every Thing. For example:</p> <pre><code>App.ThingsRoute = Ember.Route.extend({ model: function() { //Kick off query to fetch records from the server (async) App.Thing.find(); //Return only non-random posts by applying a client-side filter to the posts array return App.Thing.filter(function(hash) { if (!hash.get('name').match(/random/)) { return true; } }); } }); </code></pre> <p>See this <a href="http://jsbin.com/iyijaf/1/edit" rel="nofollow">jsbin</a> for a working example</p> <p>To learn more about filters I recommend reading the ember-data <a href="https://github.com/emberjs/data/blob/master/packages/ember-data/tests/integration/store_model_filter_test.js" rel="nofollow">store-model-filter</a> integration test</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload