QueryInterface::orConditionGroup

public 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 bikesheds:

1
2
3
4
5
6
7
8
$query = \Drupal::entityQuery('map');
$group = $query->orConditionGroup()
  ->condition('attributes.color', 'red')
  ->condition('attributes.color', 'green');
$entity_ids = $query
  ->condition('attributes.building_type', 'bikeshed')
  ->condition($group)
  ->execute();

Note that this particular example can be simplified:

1
2
3
4
$entity_ids = $query
  ->condition('attributes.color', array('red', 'green'))
  ->condition('attributes.building_type', 'bikeshed')
  ->execute();

Return value

\Drupal\Core\Entity\Query\ConditionInterface

File

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

Class

QueryInterface
Interface for entity queries.

Namespace

Drupal\Core\Entity\Query

Code

1
public function orConditionGroup();
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.