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

Use addSelect in beforePrepare #15446

Merged
merged 3 commits into from
Aug 1, 2024

Conversation

timkelty
Copy link
Contributor

@timkelty timkelty commented Jul 31, 2024

Description

In Craft 5, the \craft\elements\db\ElementQuery::EVENT_BEFORE_PREPARE event is triggered at the beginning the beforePrepare method, whereas in Craft 4, it was triggered at the end.

Because of this, code adding a select via \craft\elements\db\ElementQuery::$query->addSelect() would work in Craft 4, but would be overwritten in Craft 5, in all element types except entries (which was already adding its select via addSelect).

This PR follows the behavior of EntryQuery with all other entry types, and defines its selects with addSelect to prevent inadvertent overwriting of selects set by \craft\elements\db\ElementQuery::EVENT_BEFORE_PREPARE.

FWIW, I didn't have an issue with Commerce queries, because those still fire the event at the end of the method.

@timkelty timkelty requested a review from brandonkelly July 31, 2024 03:25
@brandonkelly brandonkelly merged commit 8669b8b into 5.x Aug 1, 2024
3 checks passed
@brandonkelly brandonkelly deleted the bugfix/use-add-select-in-before-prepare branch August 1, 2024 23:26
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