[5.6] Fix for HasManyThrough returning incorrect results with cursor(… #25015
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.29
PHP Version: 7.1.3 (MacOS 10.13.6)
Description:
Summary:
This is pull request addresses the issues reported on #22144. Using the cursor() method on a HasManyThrough relation 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.
This is a similar issue to #24096 where the problem is issue is a resulted because the intermediate model id is inserted on the query instead of the related model.
Proposed fix
cursor()
method was added toHasManyThrough
class to correct the selection of columns before they operate. This would contain the behaviour change toHasManyThrough
without affecting any other behaviours. Hence, there are no breaking changes introduced.Tests
Added and extra test to
DatabaseEloquentHasManyThroughIntegrationTest
to testcursor()
. The test asserts that the correct columns are defined.