Oihana PHP Arango

buildEdgeSubquery.php

Table of Contents

Functions

buildEdgeSubquery()  : string
Builds the inner AQL edge traversal sub-query — everything an edge `LET` wraps, already enclosed in parentheses but WITHOUT the leading `LET name =`.

Functions

buildEdgeSubquery()

Builds the inner AQL edge traversal sub-query — everything an edge `LET` wraps, already enclosed in parentheses but WITHOUT the leading `LET name =`.

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

The returned string is the parenthesized traversal:

( FOR vertex, edge IN OUTBOUND doc edge_collection [<nested LETs>] [FILTER …] [SORT …] RETURN … )

buildEdgeVariable() prefixes it with LET name = for a regular edge, while buildPolymorphicEdgeVariable() wraps several such sub-queries into a single APPEND( ( … ) , ( … ) ) array so the traversed edge collection can vary with a discriminator field of the start vertex.

Extracting this body from buildEdgeVariable() lets a polymorphic edge reuse the whole traversal machinery (direction, depth, path metadata, skinning, nested edges / joins, definition-level gating) per branch. The only addition over the historical logic is $extraConditions: a list of ready-made AQL predicates (typically the discriminator guard on the start vertex) emitted as a FILTER right after the traversal. When empty, no FILTER is emitted, so the output is byte-for-byte identical to the legacy edge sub-query.

A definition may also declare AQL::WHERE — a condition in the Field::WHEN grammar, compiled against the traversed vertex and appended to $extraConditions. It restricts WHICH vertices the relation projects, wherever the definition is used, so a consumer masking part of a collection is not contradicted by the relation of a served document:

( FOR vertex, edge IN OUTBOUND doc coll FILTER vertex.id NOT IN @hiddenTerms … )

Its value may hold an aqlBindRef(), so the retained set is decided at query time; the contract is the one Field::WHERE already carries on a Filter::MAP (a bind bound to [] retains nothing, an absent bind fails the query — never "no filter"). It composes with the polymorphic guard rather than replacing it, and is orthogonal to AQL::REQUIRES / Field::REQUIRES, which decide whether the relation is projected at all.

AQL::WHERE filters the traversal's OUTPUT; on a ranged relation (AQL::MAX_DEPTH) the walk still descends through a masked vertex, so its descendants keep being projected. AQL::PRUNE stops the walk itself — true reuses the AQL::WHERE predicate negated ("hide it and its descent"), or a condition of its own when stopping is not hiding. The two are emitted together because PRUNE stops after visiting: the vertex it stops on is still returned unless the FILTER removes it.

Parameters
$name : string|null

The logical name of the relation (used to skin the projection).

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

Configuration array for the traversal — same keys as buildEdgeVariable() (AQL::MODEL, AQL::DIRECTION, AQL::EDGES, AQL::JOINS, AQL::SKIN, AQL::MAX_DEPTH, AQL::WITH_PATH, AQL::WHERE, AQL::PRUNE, Arango::PROPERTY, …).

$startVertex : string = AQL::DOC

The AQL variable name of the starting vertex (default 'doc').

$container : ContainerInterface|null = null

The DI container used to resolve models.

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

Optional associative array used for variable initialization.

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

Ready-made AQL predicate strings emitted as a FILTER after the traversal (e.g. the discriminator guard of a polymorphic edge). Empty → no FILTER emitted (byte-identical output).

Tags
throws
Exception

If the traversal direction is invalid.

ContainerExceptionInterface

If the Edges model cannot be resolved from the container.

NotFoundExceptionInterface

If the Edges model cannot be resolved from the container.

ReflectionException
UnexpectedValueException

If $name is empty, the model is invalid, the collection is not set, or AQL::PRUNE => true has no AQL::WHERE condition to negate.

UnsupportedOperationException

If an AQL::WHERE / AQL::PRUNE condition descriptor is malformed.

ValidationException

If an AQL::WHERE / AQL::PRUNE condition attribute name is unsafe.

Return values
string

The parenthesized traversal sub-query (no leading LET name =).

On this page

Search results