Reputation: 3820
For some reason, I am unable to push records to the store. I have tried the most basic examples given from the 2.1 docs for the store.push and store.pushPayload examples.
I first tried using:
store.push(store.normalize('myModel', item));
then I tried
store.push({
data: {
id: '666',
type: 'myModel',
attributes: { name: "Bar" },
relationships: { }
}
});
The store.push when used (how I think is correct), returned nothing. I was able to run store.peekAll('myModel').mapBy('name')
, and I saw the results of the data I pushed to the store. The data never appeared in the chrome ember inspector. When I used this.store.peekAll('myModel')
in my route’s model, no results appeared whereas this.store.findAll('myModel')
resulting data would render to my templates and appear in the chrome ember inpsector.
I’m trying to avoid a trip to the server and that is why I want to hydrate the store from data cached in localStorage, and so I’m using peekAll
. Any ideas why I’m not seeing data I’m pushing to the store rendering in my templates or why the chrome ember inspector is not showing?
Edit: I forgot to mention that I am not using the default JSONApi adapter. I am using the most recent version of active-model-adapter with the most recent version of ember-data (2.1 and I tried 2.2-beta3), and ember 2.1. I also have one model that uses LocalForage adapter/serializer and that one also does not work with being pushed to directly. However everything works so long as I use findAll instead of manually push records + peekAll.
Upvotes: 1
Views: 109
Reputation: 3820
Ricardo Mendes helped me figure out what I was doing wrong. I was using the "store:main" container.
App.__container__.lookup('store:main'); // ember 1.x
This does not fly with ember 2.0. The container needs to be "service:store" as in:
App.__container__.lookup('service:store'); // ember 2.x
I was using the API correctly, just pushing to the wrong store.
Upvotes: 2