Fix for issue #629#1716
Merged
Merged
Conversation
Can't attach belongsToMany relation to models fetched with fetchAll bookshelf#629
Member
|
This just needs tests. I can add tests myself if you don't have the time for that. |
ricardograca
self-requested a review
December 28, 2017 19:49
Author
|
@ricardograca Yea, I don't have time. This is also my first time collaborating on open source project too, so forgive me. I just wanted to show a simple solution. Please note that this bug probably affects a many to many relationship too. |
ricardograca
approved these changes
Dec 29, 2017
ricardograca
left a comment
Member
There was a problem hiding this comment.
I'll be writing some tests for this after it's merged.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Can't attach belongsToMany relation to models fetched with fetchAll
#629
PR name
Introduction
Can't attach "belongsToMany" relation to models fetched with fetchAll. Will run to errors when the parent model access the collections of the child models and tries to detach.
Motivation
A many to many with a pivot table is pretty common. This bug makes bookshelf useless in this scenario.
Proposed solution
The current workaround documented in #629 is to load the child models again which is not very database friendly. The simple solution is to have the parent model recreate the the relation related data when pairing the child models with the parent models (note that before the child model fetch, a interim relation object was created and so the parent model couldn't be associated downstream of this process).
Fixes #629.
Current PR Issues
Not sure.
Alternatives considered
This seems like it would also affect many to many relationships.