QueryBase::andConditionGroup

public QueryBase::andConditionGroup()

Creates a new group of conditions ANDed together.

For example, consider a drawing entity type with a 'figures' multi-value field containing 'shape' and 'color' columns. To find all drawings containing both a red triangle and a blue circle:

1
2
3
4
5
6
7
8
9
10
$query = \Drupal::entityQuery('drawing');
$group = $query->andConditionGroup()
  ->condition('figures.color', 'red')
  ->condition('figures.shape', 'triangle');
$query->condition($group);
$group = $query->andConditionGroup()
  ->condition('figures.color', 'blue')
  ->condition('figures.shape', 'circle');
$query->condition($group);
$entity_ids = $query->execute();

Return value

\Drupal\Core\Entity\Query\ConditionInterface

Overrides QueryInterface::andConditionGroup

File

core/lib/Drupal/Core/Entity/Query/QueryBase.php, line 211

Class

QueryBase
The base entity query class.

Namespace

Drupal\Core\Entity\Query

Code

1
2
3
public function andConditionGroup() {
  return $this->conditionGroupFactory('and');
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.