Skip to content

Conversation

@bryanashley
Copy link
Contributor

Eager loading for belongsToMany was not working for two reasons.

  1. addEagerConstraints was just adding parent keys directly and not unserializing (easy fix)
  2. Once addEagerConstraints was updated to work, results were being fetched but they were not being matched to their parents. This was happening because the dictionary (used for matching) that is built, uses the pivot's foreign key value as a key for matching and because the pivot doesn't have defined mutators, it was using the serialized value as a key (in the test's example, using binary version of the value). Then when trying to match it would use the related records accessor which would unserialize and then not match. I figured it best to just mutate when the parentPivot has a mutator instead of making the Pivot record deal with mutators so it will always work (without custom pivots), and then if a user of the library does have a custom pivot they dont have to worry about extending our custom pivot, they can just extend laravel's pivot and be fine without worrying about mutators.
Bryan Ashley and others added 3 commits October 5, 2017 10:51
@bryanashley bryanashley requested a review from elliotfehr October 5, 2017 14:59
@bryanashley
Copy link
Contributor Author

@khepin Check this out when you can! (I can't add you as a reviewer for some reason).

@bryanashley bryanashley merged commit e7beba2 into master Oct 5, 2017
@elliotfehr
Copy link
Contributor

👍

@szainmehdi szainmehdi deleted the belongs-to-many-eager-bugfix branch September 13, 2022 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants