I’m trying to use entityQuery in Drupal 8 to perform an "and" within an "or" group. A simplified version of what I’m trying to do is this: Query for all apples, oranges and bananas that are ripe. The code I’d like to be able to use would look like this code.
$oQuery = Drupal::entityQuery('node'); $oOrGroup = $oQuery->orConditionGroup(); $oOrGroup->condition('type',['apple','orange'],'IN'); $oAndGroup = $oOrGroup->andConditionGroup(); $aAndGroup->condition('type','banana') ->condition('field_ripe',1); $oOrGroup->condition($oAndGroup); $oQuery->condition($oOrGroup);
This doesn’t work because andConditionGroup()
isn’t a method of ConditionInterface
.
Is there a way to do this with Drupal::entityQuery()
, or do I have to revert to using db_query()
?