I am working on caching my ember-data store to local storage. On first load I query the server load the data into the store and then load it into local storage. On subsequent page loads I pull the data from localstorage and load it into the store. I am able to do this using the pushMany method.
The store's pushMany
method requires normalized data. Payload from the server is normalized by passing it through the models serializer. Once the normalized data is in the store it seems reasonable to believe that it should be possible to pull normalized data out.
So how do you pull normalized data out of the store?
There is a _data
property on each model. The '_data' property only works with flat models. More complex models _data
property contains instantiated relationships.
I would like to avoid having to serialize/deserialize more than once.
This is my current implementation. The problem with the toJson
method is it has to load all the associations including async relations that have not been resolved. I think there is a fundamental issue regarding how ember data resolves relationship primary/foreign keys.
var posts = this.store.all('post');
// => no network request – Craicerjack