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

[5.6] Fix for HasManyThrough returning incorrect results with cursor(… #25015

Merged
merged 1 commit into from
Jul 30, 2018
Merged

Conversation

AmmarRahman
Copy link

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.

When looping through a belongsToMany association using cursor(), the models aren't correctly hydrated: they get filled with values of the pivot table. If the pivot table have columns with the same name as columns in the related model table, pivot values are used to hydrate the related model.

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 to HasManyThrough class to correct the selection of columns before they operate. This would contain the behaviour change to HasManyThrough without affecting any other behaviours. Hence, there are no breaking changes introduced.

Tests

Added and extra test to DatabaseEloquentHasManyThroughIntegrationTest to test cursor() . The test asserts that the correct columns are defined.

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.

2 participants