ember-indexeddb-adapter icon indicating copy to clipboard operation
ember-indexeddb-adapter copied to clipboard

async:true needed to load associations

Open mattmarcum opened this issue 10 years ago • 5 comments

I tried loading a route without {async:true} on the hasMany relation of the route's model...but I got the "uncaught Error: Assertion Failed: You looked up the 'model' relationship on 'model'..." error. I added the {async:true} option back to the hasMany relationship and the route loaded fine. Maybe the readme needs to be updated?

mattmarcum avatar Jul 13 '14 04:07 mattmarcum

This was my experience also.

rsutphin avatar Sep 15 '14 13:09 rsutphin

+1

cheneveld avatar Sep 18 '14 21:09 cheneveld

+1

dpfens avatar Oct 06 '14 00:10 dpfens

I noticed today that the integration tests for the library don't use async: true on their hasMany's and work fine.

I played around with it in my app a bit and found that I could only omit { async: true } if I ensured that the associated records were already cached in the store (e.g., by calling store.find('theAssociatedModel') before store.find('thePrimaryModel', 'some-id')). I tried simulating the opposite situation in the tests (via store.unloadAll('theAssociatedModel')) and still could not reproduce the error.

rsutphin avatar Nov 17 '14 21:11 rsutphin

I figured out the difference between the part of my app I was using to experiment and the tests. I was using find all in my app — store.find('the-primary-model'). The tests find a specific record: store.find('the-primary-model', 'some-id'). It appears that the adapter does recursive synchronous relationship loading only for the single record case.

rsutphin avatar Nov 17 '14 21:11 rsutphin