function QueryInterface::orConditionGroup

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/Query/QueryInterface.php \Drupal\Core\Entity\Query\QueryInterface::orConditionGroup()
  2. 8.9.x core/lib/Drupal/Core/Entity/Query/QueryInterface.php \Drupal\Core\Entity\Query\QueryInterface::orConditionGroup()
  3. 10 core/lib/Drupal/Core/Entity/Query/QueryInterface.php \Drupal\Core\Entity\Query\QueryInterface::orConditionGroup()

Creates a new group of conditions ORed together.

For example, consider a map entity with an 'attributes' field containing 'building_type' and 'color' columns. To find all green and red sheds:

$query = \Drupal::entityQuery('map')->accessCheck(FALSE);
$group = $query->orConditionGroup()
    ->condition('attributes.color', 'red')
    ->condition('attributes.color', 'green');
$entity_ids = $query->condition('attributes.building_type', 'shed')
    ->condition($group)
    ->execute();

Note that this particular example can be simplified:

$entity_ids = $query->condition('attributes.color', [
    'red',
    'green',
])
    ->condition('attributes.building_type', 'shed')
    ->execute();

Return value

\Drupal\Core\Entity\Query\ConditionInterface A condition object whose conditions will be combined with OR.

1 method overrides QueryInterface::orConditionGroup()
QueryBase::orConditionGroup in core/lib/Drupal/Core/Entity/Query/QueryBase.php
Creates a new group of conditions ORed together.

File

core/lib/Drupal/Core/Entity/Query/QueryInterface.php, line 286

Class

QueryInterface
Interface for entity queries.

Namespace

Drupal\Core\Entity\Query

Code

public function orConditionGroup();

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.