Shopify/batman — Issue #217: hasMany associations can be fooled into thinking they've been loaded
Author: tractionlabs
Created: 2011-11-08 08:38:31+00:00
State: open

hasMany uses this logic to determine if the related records have been loaded:

relatedRecords = relatedModel.get('loaded').indexedBy(self.foreignKey).get(id)
if relatedRecords.isEmpty()
load ...

My application will sometimes create an instance of the relatedModel locally, without having fetched all of the other instances from the REST interface. Then if at some point the app does in fact want to have all of the relatedRecords, the logic above causes those records to not get loaded -- the one locally created instance tricks the association into thinking that all the records were loaded. Now that I know what's going on, I guess for now I can work around this problem by always loading the related records before creating a local instance, but this isn't an ideal solution.