Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force ember data store.find to load from server

Is there a nice way to force Ember Data to load the resource from server eaven if it has it already in store ?

I have a simple show user action that do store.find('users',id) the model is loaded only once at first attempt to display a page the second time i go my model is loaded from the store which is normal ember data behaviour i know. However i need to load it each time.

edit: the only way i found is to do this :

@store.find('user',{id: params.user_id}).then (users)->
  users.get('firstObject')

however it forces me to implement a "fake" show action on my index action ...

like image 598
Piotr Avatar asked Nov 11 '13 13:11

Piotr


Video Answer


2 Answers

I think this... http://emberjs.com/api/data/classes/DS.Model.html#method_reload

model.reload()

Good luck

like image 164
Edu Avatar answered Sep 22 '22 06:09

Edu


Additionally you can call getById which will return any instance of that record that exists, or null, then call unloadRecord to remove it from the cache. I like Edu's response as well though, then I wouldn't have to worry about the record existing somewhere else. Maybe I'd use getById then reload that way any references that had a reference to the user got updated. (pardon my errant coffeescript, if it's wrong).

user = @store.find('user', params.user_id)
if (user) 
  @store.unloadRecord(user)
like image 22
Kingpin2k Avatar answered Sep 25 '22 06:09

Kingpin2k