lundi 13 avril 2015

ember find() keeps making api call even after I've stored it in DS.Store

I have a model with a custom adapter. I've got my adapter populating the application store but when my component calls find('model') it does another server request -- which I do not want. The docs said that if something's recorded in the store, then it will get it from cache.



SongAdapter = ApplicationAdapter.extent
data = somePayload
new Ember.RSVP.Promise (resolve, reject) =>
path = 'some/endpoint/songs'
myPOST(path, data, @, options).then (data) ->
_.each data.songs, (entity) ->
entity.id = entity.songId
store.push('song', store.normalize('song', entity))
Ember.run(null, resolve, data)
, (jqXHR) ->
jqXHR.then = null
Ember.run(null, reject, jqXHR)


When my component loads I fetch the initial songs like this:



getSongHistory: Ember.on 'didInsertElement', ->
@store.find('song').then (data) =>
@set('songHistory', data.get('content'))


I'm missing something. I thought that find() was supposed to search the cache first, then if empty delegate to the findAll() method in the adapter. What am I missing?





Aucun commentaire:

Enregistrer un commentaire