Updated options fetchRelated() passed to Collection#fetch() #271
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
add: true didn't seem to do anything. Collection.fetch() only checks for updated. Only if it exists, does Collection.update() get called, which then checks for add option... but it defaults to true anyways. I'm presuming that this is a bug and update: true was intended.
Additionally, I added emove: false to prevent Collection#update() from removing existing models. This is important if some models were grabbed from cache and other models relied on fetchRelated() calling fetch(). If remove != false, then the cached models would be removed
For example, if you do:
where:
Then, BB Relational will, eventually:
Create Child objects for id 1 and id 2, but not add them to the Parent[id=1].children collection, then send a Parent[id=1].children.fetch() request off. The return will be parsed and added to the collection.
Asynchronously, fetchRelated() is called for Parent[id=2], which already has children id=1, and id=2 added (though pre-fetch). It loops through and determines that only child id=3 needs to be fetched, so it sends the fetch request off. But, without update: true, then fetch() calls reset(), which will wipe everything out. Without remove: false, then fetc() calls update() which will remove all items not added, essentialy acting like reset.