Oihana PHP Arango

buildPolymorphicEdgeVariable.php

Table of Contents

Functions

buildPolymorphicEdgeVariable()  : string
Builds a single AQL 'LET' subquery for a *polymorphic* edge — an edge whose traversed collection is chosen at query time from a discriminator field of the start vertex (the parent document).

Functions

buildPolymorphicEdgeVariable()

Builds a single AQL 'LET' subquery for a *polymorphic* edge — an edge whose traversed collection is chosen at query time from a discriminator field of the start vertex (the parent document).

buildPolymorphicEdgeVariable(string|null $name[, array<string|int, mixed> $definition = [] ][, string $startVertex = AQL::DOC ][, ContainerInterface|null $container = null ][, array<string|int, mixed> $init = [] ]) : string

The whole branch machinery (guarding, per-branch permission gating, the FALLBACK branch, the APPEND combine) lives in the shared buildPolymorphicRelationVariable(); this function only supplies the per-branch builder, which delegates to buildEdgeSubquery() (already a parenthesized traversal). Each branch is a full edge definition, so it may declare its own AQL::DIRECTION, AQL::MAX_DEPTH, etc.

The resulting LET always holds an array — exactly like a regular edge — so the projection layer (aqlFieldObject()) unwraps it with FIRST() for a Filter::EDGE or keeps the whole array for a Filter::EDGES.

Example output (two branches):

LET rel = APPEND(
  ( FOR vertex, edge IN OUTBOUND doc warehouse_edges
      FILTER doc.kind == "warehouse"
      RETURN { _key: vertex._key, name: vertex.name } ) ,
  ( FOR vertex, edge IN OUTBOUND doc company_edges
      FILTER doc.kind == "company"
      RETURN { _key: vertex._key, name: vertex.name } )
)
Parameters
$name : string|null

The edge field name — also the default LET variable name.

$definition : array<string|int, mixed> = []

The polymorphic edge definition. Keys:

  • Arango::DISCRIMINATOR (string) Start-vertex field path deciding the branch (required).
  • Arango::MAP (array) Non-empty type => edge-definition table (required).
  • Arango::UNIQUE (string|null) Optional LET variable name, overrides $name.
  • Arango::SOURCE (string|null) Optional absolute path holding the traversal start-vertex _id; the traversal then departs from doc.<source> while the discriminator STAYS resolved on the parent document (doc.<discriminator>).
  • Arango::FALLBACK (array|null) Edge definition for unmatched discriminator values (null = none).
$startVertex : string = AQL::DOC

The AQL variable name of the start vertex.

$container : ContainerInterface|null = null

Optional DI container used to resolve branch models.

$init : array<string|int, mixed> = []

Optional associative array used for variable initialization.

Tags
throws
Exception

If a branch traversal cannot be built.

ContainerExceptionInterface

If a branch model cannot be resolved from the container.

NotFoundExceptionInterface

If a branch model cannot be found in the container.

ReflectionException
UnexpectedValueException

If $name is empty, or the definition lacks a non-empty Arango::MAP / Arango::DISCRIMINATOR.

since
1.0.0
author

Marc Alcaraz

Return values
string

The complete AQL 'LET' statement.

On this page

Search results