Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Fix for issue #629 #1716
Can't attach belongsToMany relation to models fetched with fetchAll
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.
A many to many with a pivot table is pretty common. This bug makes bookshelf useless in this scenario.
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).
Current PR Issues
This seems like it would also affect many to many relationships.