[5.6] Fix for HasManyThrough returning incorrect results with chunk()…#24096
Merged
Conversation
Author
|
No, I have not tackled the cursor() issue. I will attempt to do a pull request to fix it without breaking anything within the next couple of days. |
This was referenced Jul 24, 2018
Author
|
@sylouuu A fix for cursor has been merged into 5.6 branch |
|
@iceheat Awesome, thanks! Is the merged PR you talk about also works for BelongsToMany relationships? |
Author
|
@sylouuu The fix was for HasManyThrough. I have no knowledge of BelongsToMany causing issue. It would be helpful if you submit a test highlighting the issue. |
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.
Laravel Version: 5.6.17
PHP Version: 7.1.3 (MacOS 10.13.4)
Description:
Summary:
This is pull request addresses the issues reported on #21774. Using the
chunk()method on aHasManyThroughrelation object returns incorrect results. This is due to to the fact that Eloquent QueryBuilder attempts to hydrate the the related model with intermediate model attributes.With the current codebase
get()method has fixes the issue by getting an instance of the builder with the correct table and columns selected to overcome the issue. This can be demonstrated by the different model structure that would be retrieved when running$country->posts()->get()vs$country->posts()->getQuery()->get()The same issue is manifested when using
each()method. This is becauseeach()uses the underlyingchunk()method during its runtime.Proposed fix
chunk()andeach()methods were added toHasManyThroughclass to correct the selection of columns before they operate. This would contain the behaviour change toHasManyThroughwithout affecting any other behaviours. Hence, there are no breaking changes introduced.Tests
Added two extra tests to
DatabaseEloquentHasManyThroughIntegrationTestto testchunk()andeach(), where the models are checked to have the correct columns defined.