ember.js - Clear data from Ember's Store before doing findAll -
using ember 1.11 have search function working run parameterized find(), want able go state before find, records there before. in app, records api returns no query parameters.
my route's model hook
model: function(params) { if (params.q) { return this.store.find('project', params); } else { return this.store.findall('project'); } }
however, happens when user goes (by using action clears query parameter):
backtomyprojects: function() { this.set('q', null); }
(this jsbin example @lolmaus helped me working) records still in store, when findall(), gets both sets of records, when want clear out store, use records findall(). server api call happening correctly in both places, it's model hook called no params after it's been called once params, store has records in it.
so tried adding this.store.unloadall('project')
error after going parameterized query, 1 without parameters.
updated model hook
model: function(params) { if (params.q) { return this.store.find('project', params); } else { this.store.unloadall('project'); return this.store.findall('project'); } }, //this isn't new, forgot put earlier. when query param modified, model hook called again (as understand it). queryparams: { q: { refreshmodel: true } }
error message
error while processing route: projects assertion failed: calling set on destroyed object error: assertion failed: calling set on destroyed object @ new error (native) @ error.embererror (http://localhost:4200/assets/vendor.js:22615:21) @ object.ember.default.assert (http://localhost:4200/assets/vendor.js:15716:13) @ object.set (http://localhost:4200/assets/vendor.js:26367:22) @ exports.default.mixin.mixin.create.set (http://localhost:4200/assets/vendor.js:41034:20) @ ember.object.extend.flushcanonical (http://localhost:4200/assets/vendor.js:69680:14) @ ember$data$lib$system$relationships$state$has_many$$manyrelationship.flushcanonical (http://localhost:4200/assets/vendor.js:71436:22) @ queue.invoke (http://localhost:4200/assets/vendor.js:11425:18) @ object.queue.flush (http://localhost:4200/assets/vendor.js:11490:13) @ object.deferredactionqueues.flush (http://localhost:4200/assets/vendor.js:11295:19)
in else
condition, use find()
again instead of findall()
gets store:
return this.store.find('project');
update: never mind, in 1.11 , up, call findall() under covers anyway. not sure how force not use store.
so far, have wrapped unloadall() in ember.run, , appears work, i'm not sure why necessary:
model: function(params) { if (params.q) { return this.store.find('project', params); } else { var _this = this; ember.run(function() { _this.store.unloadall('project'); }); return this.store.find('project'); } }
Comments
Post a Comment