Closed zshnr closed 9 years ago
@zshnr I believe shouldReloadAll is a method from Ember Data 1.13. This library is not compatible yet with this version. You can find a branch where I started making it compatible, but that was before the recently published blogpost on the changes made in 1.13.
With that blogpost it should be more clear how to upgrade the adapter. If you would like to help with the compatibility, please go ahaed :)
@frederikbosch ah, I had a feeling that is what was breaking. Thanks a lot for the clarification :)
I would love to help you with this, unfortunately I'm not only a junior Ember developer, I'm a junior developer. I have no idea where to start helping you even though I would really like to.
@frederikbosch So I changed ember-data to 1.0.0.beta-18 and still the same issue. (I removed the shouldReloadAll
hook from adapter.js the rest of the code is still the same.
I noticed though that this problem is with using the filter method. If I use the find
method, then the data loaded on the other route is the updated data.
Is there any way I can filter data without using the filter
method? thanks a lot!
@zshnr Yes there is. From the top of my head.
export default Ember.Route.extend({
setupController: function (controller, model) {
this._super(controller, model);
controller.set('filtered', model.filterBy('isOnSale', true));
},
model: function () {
return this.store.find('product');
}
});
@zshnr I will have a look at the filter
method. Which version of Ember are you using? Be aware of the fact that filter will be deprecated in Ember 2.0.0 and moved to an addon.
@frederikbosch I downgraded to: ember: 1.12.0
& ember-data 1.0.0.beta18
. Thanks a lot for checking it out & the heads up on the impending deprecation :)
@frederikbosch missed your previous post completely, let me try that. Thanks!
Edit:
Tried it out. It may need to be tweaked a bit because it was returning all the items in the product model. However, I found that this worked:
export default Ember.Route.extend({
model: function() {
var store = this.store;
return store.find('product').then(function() {
return store.filter('product', function(product) {
return product.get('isInCart');
});
});
}
});
Thanks a lot for your help! :)
@zshnr No problem. Will leave this issue open until I have created a test that shows the problem or proves that the problem must on your side.
@zshnr The issue on the store.find
method, is that still Ember Data 1.13? Or did your downgrade to a 1.0 beta x?
store.find works on 1.0.beta.18. But it breaks in 1.13.2 (that is the one I tried). It was store.filter that was still breaking in 1.0.beta.18
@zshnr The behaviour of the adapter is correct for store.filter
in 1.0 beta 18. Do not forget to pass a query, otherwise Ember Data will not ask the adapter to lookup records.
Since there is already an issue on Ember Data 1.13, I will close this one.
I’m prototyping a store front. I’m loading all the product model data by pushing it to localstorage (using the localforage adapter) in the application route when the app starts for the first time:
adapters/application.js
routes/application.js
Now, on the index route I change the attribute (like say
isOnSale
) by pressing a button that saves it to localstorage using.save()
The changes persist just fine on the index route, but when I goto another route (say /sale), the
isOnSale
that is shown is the old one that was pushed in the initialization of the app, not the updated one from store.The code for the other route is:
routes/sale.js
Is this a problem with the adapter?