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.
Description
In Craft 5, the
\craft\elements\db\ElementQuery::EVENT_BEFORE_PREPARE
event is triggered at the beginning thebeforePrepare
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.