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

[12.x] Query builder PDO fetch modes + columns fix #54734

Merged
merged 26 commits into from
Feb 21, 2025

Conversation

bert-w
Copy link
Contributor

@bert-w bert-w commented Feb 20, 2025

Same PR as #54443 , with the addition of a fix for #54708 + testcase.

The issue was caused by my assumption that pluck-arguments should override the $this->columns property in all situations. This however is not the case since you can do a:

$query->select(/* some-query AS my_column */)->pluck('my_column');

therefore requiring the custom named column. So the code to set the columns should remain:

$this->columns ??= ...

Copy link

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@bert-w bert-w marked this pull request as ready for review February 20, 2025 18:46
@shaedrich
Copy link
Contributor

shaedrich commented Feb 20, 2025

Have you considered allowing to set the fetch mode via query() as I suggested in #54443 (comment)?

User::query(PDO::FETCH_UNIQUE)->select(['id','users.*'])->get();

@bert-w
Copy link
Contributor Author

bert-w commented Feb 20, 2025

Have you considered allowing to set the fetch mode via query() as I suggested in #54443 (comment)?

User::query(PDO::FETCH_UNIQUE)->select(['id','users.*'])->get();

Yes I did; I dont think this is a feature that should be on the forefront that much so I thought a simple chained function would be better. Also when using DB::table('...') statements, there is no ->query()-> function anywhere so that might introduce some complexity. Same with how you can call User::where(...)->orderBy(...)->get() without ever having to use query().

A fetchUsing(...) is just the same across the board.

@shaedrich
Copy link
Contributor

Yeah, that makes sense 👍🏻

Maybe, this can be additionally added as a convenience feature in a follow-up PR if it appears to be beneficial 🤔

@taylorotwell taylorotwell merged commit fba73b5 into laravel:master Feb 21, 2025
39 checks passed
@macropay-solutions
Copy link

macropay-solutions commented Mar 3, 2025

@bert-w Same question as here #54443 (comment)

Will this work in Laravel 8-11 with onceWithColumns function with just ->fetchAll(...$fetchUsing) code (and related params) change?

@macropay-solutions
Copy link

@shaedrich

Yeah, that makes sense 👍🏻
Maybe, this can be additionally added as a convenience feature in a follow-up PR if it appears to be beneficial 🤔

That would need to be added in Laravel 13 as it would be a breaking change in the definition of the query function and of the subsequent functions called with that param.

@shaedrich
Copy link
Contributor

Yeah, thanks for the hint 👍🏻

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.

4 participants