Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Belongs to many eager bugfix #12

Merged
merged 3 commits into from
Oct 5, 2017
Merged

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
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants