I'm using the new router and ember data rev 11.
I have a need to force ember-data to re-load data for a record from the server. Using App.MyRecord.find
(2) in setInterval
function loads the data from the client local store.
How can I reload the data from the server?
To refresh your ember model you can use this. refresh(); . Actions should be on controller not on route accordingly to last RFC discussion about route-action helper. I would recommend to move the refreshModel() action to controller.
The most important thing to know is that Ember. js is completely backend-agnostic. You could write this part just as well in Ruby, PHP, Python or any other server language.
In Ember Data, models are objects that represent the underlying data that your application presents to the user. Note that Ember Data models are a different concept than the model method on Routes, although they share the same name.
I just pushed record.reload()
to Ember Data. This will ask the adapter to reload the data from the server and update the record with the new data.
reload()
on a record if it has completed loading and has not yet been modified. Otherwise, the returned data will conflict with the modified data. In the future, we will add support for a merge hook to address these sorts of conflicts, which will allow reload()
in more record states.reload()
and change or save the record before the adapter returns the new data, you will get an error for the same reason. The error currently looks something like Attempted to handle event 'reloadRecord' on <Person:ember263:1> while in state rootState.loaded.updated.uncommitted.
. Basically, this means that your record was in the "updated but uncommitted" state, and you aren't allowed to call reload()
outside of the "loading and unmodified" state.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