You are here

function relation_query_add_related in Relation 8.2

Same name and namespace in other branches
  1. 8 relation.module \relation_query_add_related()

Add a related entity to the query.

@todo rename. / extend class ala RelationQuery::related()


QueryInterface $query: The query object.

string $entity_type: Entity type of the related entity.

int $entity_id: (optional) Entity id of the related entity. Can be an array of entity IDs.

int|null $delta: (optional) The index of the related entity within the requested relation(s).

Return value

Drupal\Core\Entity\Query\QueryInterface The query object

2 calls to relation_query_add_related()
RelationRepository::relationExists in src/Entity/RelationRepository.php
Checks if a relation exists.
relation_query in ./relation.module
Returns a query object to find related entities.


./relation.module, line 163
Describes relations between entities.


function relation_query_add_related(QueryInterface $query, $entity_type, $entity_id = NULL, $delta = NULL) {
  $group = $query
    ->condition('endpoints.%delta.target_type', $entity_type, '=');
  if (isset($entity_id)) {
    $operator = is_array($entity_id) ? 'IN' : '=';
      ->condition('endpoints.%delta.target_id', $entity_id, $operator);
  if (isset($delta)) {
      ->condition('endpoints.%delta', $delta, '=');
  return $query;