Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

findAll Resolving before it is done Updating #3483

Closed
eneuhauser opened this issue Jul 2, 2015 · 7 comments
Closed

findAll Resolving before it is done Updating #3483

eneuhauser opened this issue Jul 2, 2015 · 7 comments

Comments

@eneuhauser
Copy link

I'm using ember-data 1.13.4 with the JSONAPISerializer/Adapter. I'm trying this.get('store').findAll('foo').sortBy('bar'), but it's returning an empty array. The findAll is resolving before the array is populated and the sortBy is creating a new array from the incomplete record array.

Upon inspection of this.get('store').findAll('foo').then(function(arrayProxy) {}), the arrayProxy is marked isUpdating === true. If I wait for it to be done updating, I can then apply my sort, but the original sortBy should work.

Edit:

In my adapter, I have shouldReloadAll return false, but this still happens when returning true and when calling findAll('foo', { reload: true }).

Additionally, I also want to have shouldBackgroundReloadAll return false, but when false, the initial network request is never made. If I change the logic to the following:

shouldBackgroundReloadAll: function(store, recordArray) {
  return recordArray.length === 0;
}

The network request is made the first time, but subsequent times do not clear the isUpdating flag. Instead of checking for isUpdating false, I have to check that the length is greater than 0. When set to true, the network request is made every time.

@jmurphyau
Copy link
Contributor

Try passing { reload: true } as the second parameter.. I had the same issue as you (array returned 0 items but isUpdating = true) and adding this second parameter fixed it for me.

@eneuhauser
Copy link
Author

Thanks @jmurphyau, but that didn't work for me. Also, I'd rather not do a reload. I have some volatile bits of information, but I'm also loading up lists of items that don't change very often, so I would like to reduce the network chattiness.

@piotrpalek
Copy link

It seems it doesn't work for me either, I am loading the foo collection by running this.store.findAll('foo') and then trying this.store.findAll('foo').toArray() and it returns an empty array as well. Maybe I just don't get how to use it to get the data quickly the 2nd time, any help?

@sir-dunxalot
Copy link

I also experienced this issue with Ember Data v1.13.5 when doing a findAll('some-model') call and { reload: true } fixed it.

@jmurphyau - What's the logic/reason that makes this the solution (or at least workaround).

@sir-dunxalot
Copy link

FYI, the adapter I am using is Emberfire's FirebaseAdapter.

@tpitale
Copy link
Contributor

tpitale commented Jan 11, 2016

I'm also experiencing this when doing (from a route):

this.get('store').findAll('model').then(function(collection) {collection.toArray()});

Anything that calls toArray appears to only return a subset of records. You can even do get('length') to see how few it may return (7 out of 46, in my case).

However, if you check it "later" using something like setTimeout after 1 second, the length is correct.

Update: using {reload: true} worked for me.

@pangratz
Copy link
Member

pangratz commented May 4, 2016

I am closing this issue since the documentation should have improved now that #4338 has been merged. Please feel free to reopen if you think this is still not documented sufficiently. Thanks!

@pangratz pangratz closed this as completed May 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants