Problem/Motivation
When wrapping multiple OR groups inside an AND group in an entity query, you get the wrong (empty) results.
Steps to reproduce
1. Use a multi-value field, such as a term reference, on an entity that has terms from two vocabularies.
2. Build $and = $query->andConditionGroup() and add two orConditionGroup()s to it, each with a condition on that field.
3. Add $and to the query and execute it. It returns 0 results. Adding the same OR groups directly to $query returns the entity.
See the test.
Proposed resolution
Add a strtoupper for the AND conjunction, same as we have for the OR conjunction
Remaining tasks
Review and discuss
User interface changes
None
Introduced terminology
None
API changes
None
Data model changes
None
Release notes snippet
Issue fork drupal-3631067
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
lendudePushed a test and a fix.
Disclaimer: Used Claude to help write some stuff
Comment #4
daffie commentedLooks good to me.
The code change has testing for it.
To me it is RTBC.
Comment #5
alexpottNice find! I've searched the core codebase and confirmed that this is the only place we're not wrapping a comparison against a conjunction with strtoupper - for example we already do
$and = strtoupper($this->conjunction) == 'AND';in \Drupal\Core\Config\Entity\Query\Condition::compile()Committed 4a2327e and pushed to main. Thanks!
Committed 8e8fb28 and pushed to 12.0.x. Thanks!
Committed 5910ba0 and pushed to 11.x. Thanks!
Committed d59c530 and pushed to 11.5.x. Thanks!
Backported to 11.5.x as a low risk and nice bug fix.