My application embeds initial data into the html so that Ember does not need to send extra http requests on initialization. I am using the latest Ember data and I have not been able to succesfully take a JSON object, which is the same as Active Model Serializer returns when you save or create a record, and load it into the store.
I am currently trying these methods with no success:
In a route -
this.get('store').load(App.Post, data)
and
this.get('store').loadMany(App.Post, data)
I also use Pusher that sends me the JSON (generated by Active Model Serializer) for an updated object and the callback in my route currently looks like this.
refresh: function(data) {
var json = data
var store = this.get('store')
var type = App.Post
var id = data.reply.id
Ember.run(this, function(){
store.adapterForType(App.Post).didFindRecord(store, type, json, id);
});
}
Has anyone successfully done this? I know Discourse is not using Ember Data so their solution is different. I really appreciate any help in the matter. Thanks
These questions have both been discussed elsewhere. I'm going to give you pointers to the other discussions, so that you can follow along with the conversation as people improve the current answers:
actions: {
save() {
let json = this.get('json');
json.id = '123123'; // id is required in order to use store.push
let store = this.get('store');
this.set('myModel', store.push(store.normalize('myModel', json)));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With