Oihana PHP Arango

Edges extends Documents uses EdgesPurgeTrait, EdgesCountTrait, EdgesDeleteTrait, EdgesExistTrait, EdgesGetTrait, EdgesInsertTrait

Represents a collection of ArangoDB edges connecting vertices.

This model extends Documents and provides additional methods to manage edges between vertices (from and to).

It supports:

  • Automatic initialization of vertex references (from and to).
  • Counting edges based on vertex filters.
  • AQL query generation for counting edges with bind variables.
Tags
author

Marc Alcaraz (eKameleon)

version
1.0.0

Table of Contents

Constants

EDGE_SUFFIX  : string = '_e'
The suffix used for edge fields in queries.
FIELDS  : string = 'fields'
The 'fields' key for initialization arrays.
JOIN_SUFFIX  : string = '_j'
The suffix used for join fields in queries.
UNIQUE_SUFFIX  : string = '_u'
The suffix used for unique fields in queries.
ARRAY_VAR  : string = '__arr'
The AQL variable holding the new array value written back by the `UPDATE`.
ELEMENT_VAR  : string = '__el'
The AQL variable holding the element targeted by an item key, looked up by {@see arrayMove()} before it rebuilds the final order.
INDEX_VAR  : string = '__i'
The AQL variable holding the index of the element being renumbered, bound by the loop {@see arrayRank()} runs over the final array.
KEY_VAR  : string = '__k'
The AQL variable holding the item key currently looked up by {@see arrayReorder()}, bound by the loop it runs over the requested order.
ORDERED_VAR  : string = '__ord'
The AQL variable holding the elements {@see arrayReorder()} resolved from the requested order, before the ones it did not mention are appended back.
RANKED_VAR  : string = '__pos'
The AQL variable holding the renumbered array — the one written back when the field declares an {@see Arango::POSITION_KEY}, in place of {@see self::ARRAY_VAR}.
REMAINDER_VAR  : string = '__rm'
The AQL variable holding the array **minus** the element being moved, from which {@see arrayMove()} rebuilds the final order.
NORMALIZED_MARKERS  : array<string|int, mixed> = [\oihana\arango\enums\Field::ALTERS, \oihana\ar...
The scalar `Field::` markers copied **verbatim** from the raw field options into the normalized definition produced by {@see normalizeFieldDefinition()}.

Properties

$arrays  : array<string|int, mixed>
The per-field embedded-array configuration, normalised to `[ field => [ Arango::MODE => ArrayMode::*, Arango::COUNTER => ?string, Arango::ITEM_KEY => ?string, Arango::POSITION_KEY => ?string ] ]`.
$fields  : array<string, mixed>
The fields definitions to return in get/list methods.
$purge  : string|null
The purge mode for this edge collection.
$skinFields  : array<string, array<string, mixed>>
Optional per-skin alternative projections for the model's own fields.
$_purge  : string|null

Methods

__construct()  : mixed
Creates a new Edges instance.
__destruct()  : mixed
Invoked when the Edges instance is removed.
arrayContains()  : bool
Checks whether the array `field` of a single document (identified by `owner`) contains `value`.
arrayDefaults()  : array<string, array<string|int, mixed>|int>
Returns the default seed for the declared embedded array fields: each array field defaults to `[]`, and each declared counter to `0`.
arrayInsert()  : object|null
Adds one or several values to the array `field` of a single document.
arrayMove()  : object|null
Moves an existing `value` to the given zero-based `position` inside the array `field`.
arrayPurgeRef()  : array<string|int, object>|int
Removes a `value` from the array `field` of **every** document of the collection that contains it — typically to purge a now-deleted reference.
arrayRemove()  : object|null
Removes one or several values from the array `field` of a single document.
arrayReorder()  : object|null
Reorders the array `field` from a list of item keys — the whole new order in a single call, where {@see arrayMove()} moves one element at a time.
arrayUpdate()  : object|null
Merges a partial `patch` into the element of the array `field` carrying the given item key — an **in-place edit**, where the other operations only add, remove or reorder whole elements.
countAnyVertices()  : int
Counts all unique vertices connected in any direction from the given vertex.
countEdges()  : int
Counts the number of edge documents matching the specified vertices.
countInboundVertices()  : int
Counts all unique inbound vertices connected to the given 'to' vertex.
countOutboundVertices()  : int
Counts all unique outbound vertices connected from the given 'from' vertex.
countVertices()  : int
Counts all vertices connected with a specific direction.
deleteEdge()  : array<string|int, mixed>|object|null
Delete an edge document connecting two vertices.
deleteEdgeFrom()  : array<string|int, mixed>|object|null
Delete all edges where the `_from` vertex matches the given identifier.
deleteEdges()  : array<string|int, mixed>|object|null
Delete all edges connected to a specific vertex, either `_from` or `_to`.
deleteEdgeTo()  : array<string|int, mixed>|object|null
Delete all edges where the `_to` vertex matches the given identifier.
diagnose()  : array<string|int, DiffReport>
Compares everything this model declares with the server state, without touching anything — the read-only half of {@see repair()}.
existEdge()  : bool
Checks if an edge exists between the given '_from' and '_to' vertices.
existEdgeFrom()  : bool
Checks if at least one edge exists from the specified 'from' vertex.
existEdgeTo()  : bool
Checks if at least one edge exists to the specified 'to' vertex.
getAnyVertices()  : object|array<string|int, mixed>|null
Retrieves all vertices connected in any direction from the given vertex.
getFirstAnyVertex()  : object|array<string|int, mixed>|null
Retrieves the first vertex connected in any direction from the given vertex.
getFirstInboundVertex()  : object|array<string|int, mixed>|null
Retrieves the first inbound vertex connected to the given 'to' vertex.
getFirstOutboundVertex()  : object|array<string|int, mixed>|null
Retrieves the first outbound vertex connected from the given 'from' vertex.
getInboundVertices()  : object|array<string|int, mixed>|null
Retrieves all inbound vertices connected to the given 'to' vertex.
getOutboundVertices()  : object|array<string|int, mixed>|null
Retrieves all outbound vertices connected from the given 'from' vertex.
getVertices()  : object|array<string|int, mixed>|null
Retrieves all vertices connected with a specific direction.
hasAnyVertex()  : bool
Checks if a specific target vertex is a neighbor in any direction.
hasInboundVertex()  : bool
Checks if a specific target vertex is an inbound neighbor of the start vertex.
hasOutboundVertex()  : bool
Checks if a specific target vertex is an outbound neighbor of the start vertex.
initializeArrays()  : static
Initialize the per-field embedded-array configuration from the `arrays` option.
initializeDocumentsMethods()  : static
Initialize the Documents HTTP methods signals.
initializeFields()  : static
Initialize fields definitions from an associative array.
initializeInvalidations()  : static
Connects `afterInsert` / `afterUpdate` / `afterDelete` to the declared services.
initializePurge()  : static
Initialize the purge property from an array or string.
initializeSkinFields()  : static
Initialize the per-skin projections registry from an associative array.
insertEdge()  : object|null
Inserts a new edge document connecting two vertices, optionally checking for uniqueness.
prepareQueryFields()  : array<string, array<string|int, mixed>>|null
Prepares query fields based on internal definitions and optional skin filter.
repair()  : array<string|int, DiffReport>
Reconciles the server with everything this model declares — the acting half of {@see diagnose()}:
returnFields()  : string
Generates an AQL document expression or LET statement with the selected fields.
arrayCounter()  : string|null
Returns the configured length-counter attribute of an array field, or null.
arrayItemKey()  : string|null
Resolves the item-key attribute of an array field — the attribute carried by each element that identifies it — honouring an optional per-call `itemKey` override, then the declared configuration, then defaulting to null.
arrayMode()  : string
Resolves the {@see ArrayMode} of an array field, honouring an optional per-call `mode` override, then the declared configuration, then defaulting to LIST.
arrayPositionKey()  : string|null
Resolves the position-key attribute of an array field — the attribute of each element carrying its rank — honouring an optional per-call `positionKey` override, then the declared configuration, then defaulting to null.
arrayWith()  : string
Builds the `WITH { ... }` object clause: the array field, its optional length counter, and the `modified` timestamp unless `touch` is disabled.
countEdgesQuery()  : string
Generates the count query and fill the binds array reference.
ensureArrayDefaults()  : Closure|null
Builds an `ensure` closure that seeds the declared array fields to `[]` (and their counters to `0`) for any missing key of a document being created, then applies the optional user-supplied `ensure`. Returns the user closure unchanged when no array field is declared (so models without `AQL::ARRAYS` are untouched).
arrayErasedKeys()  : array<int, string>
The attributes a patch asks to be taken away — the keys it carries at null.
arrayRank()  : array{0: array, 1: string}
Appends the renumbering `LET` to the given clauses when the field declares an {@see Arango::POSITION_KEY}, and returns them along with the AQL variable holding the array to write back.
filterFieldsBySkin()  : array<string, mixed>
Filters fields based on an optional skin.
generateUniqueKey()  : string|null
Generates a unique key for special filters like edges, joins, or unique names.
hasVertex()  : bool
Private helper to check for vertex existence in a specific direction.
normalizeFieldDefinition()  : array<string, mixed>|null
Normalize a field definition into a structured array for queries.
runArrayUpdate()  : object|null
Compiles and executes a single-document array UPDATE (`FOR ... FILTER ... LET ... UPDATE ... RETURN NEW`), emitting the update signals around the write.

Constants

EDGE_SUFFIX

The suffix used for edge fields in queries.

public string EDGE_SUFFIX = '_e'

FIELDS

The 'fields' key for initialization arrays.

public string FIELDS = 'fields'

JOIN_SUFFIX

The suffix used for join fields in queries.

public string JOIN_SUFFIX = '_j'

UNIQUE_SUFFIX

The suffix used for unique fields in queries.

public string UNIQUE_SUFFIX = '_u'

ARRAY_VAR

The AQL variable holding the new array value written back by the `UPDATE`.

protected string ARRAY_VAR = '__arr'

Double-underscored to stay out of the way of any user-supplied bind or alias.

ELEMENT_VAR

The AQL variable holding the element targeted by an item key, looked up by {@see arrayMove()} before it rebuilds the final order.

protected string ELEMENT_VAR = '__el'

It is null when no element carries the requested key, which the move guards against so an unknown key is a no-op rather than a phantom insertion.

INDEX_VAR

The AQL variable holding the index of the element being renumbered, bound by the loop {@see arrayRank()} runs over the final array.

protected string INDEX_VAR = '__i'

KEY_VAR

The AQL variable holding the item key currently looked up by {@see arrayReorder()}, bound by the loop it runs over the requested order.

protected string KEY_VAR = '__k'

ORDERED_VAR

The AQL variable holding the elements {@see arrayReorder()} resolved from the requested order, before the ones it did not mention are appended back.

protected string ORDERED_VAR = '__ord'

RANKED_VAR

The AQL variable holding the renumbered array — the one written back when the field declares an {@see Arango::POSITION_KEY}, in place of {@see self::ARRAY_VAR}.

protected string RANKED_VAR = '__pos'

REMAINDER_VAR

The AQL variable holding the array **minus** the element being moved, from which {@see arrayMove()} rebuilds the final order.

protected string REMAINDER_VAR = '__rm'

NORMALIZED_MARKERS

The scalar `Field::` markers copied **verbatim** from the raw field options into the normalized definition produced by {@see normalizeFieldDefinition()}.

private array<string|int, mixed> NORMALIZED_MARKERS = [\oihana\arango\enums\Field::ALTERS, \oihana\arango\enums\Field::DEFAULT, \oihana\arango\enums\Field::ELSE, \oihana\arango\enums\Field::FORMAT, \oihana\arango\enums\Field::NAME, \oihana\arango\enums\Field::NULLABLE, \oihana\arango\enums\Field::PATH, \oihana\arango\enums\Field::PATHS, \oihana\arango\enums\Field::PROPERTY, \oihana\arango\enums\Field::QUOTED, \oihana\arango\enums\Field::RAW, \oihana\arango\enums\Field::REQUIRES, \oihana\arango\enums\Field::SELF_REQUIRES, \oihana\arango\enums\Field::SCOPE, \oihana\arango\enums\Field::WHEN, \oihana\arango\enums\Field::WHERE]

⚠️ Single source of truth — register every new marker here. A scalar Field:: marker absent from this list is silently stripped during projection normalization, so it never reaches the query builders nor the permission gates (this is exactly how Field::SELF_REQUIRES was first lost). The structural markers are built separately and must NOT be added here: Field::FILTER (seeded from the already-resolved filter), Field::FIELDS / Field::EDGES / Field::JOINS (sub-projections attached after the recursive walk), Field::UNIQUE (generated), and the skin buckets (AQL::SKIN_FIELDS).

Field::DEFAULT is intentionally kept even though it resolves to null (Field::DEFAULT === null), so the copy is byte-for-byte identical to the historical literal table.

Properties

$arrays

The per-field embedded-array configuration, normalised to `[ field => [ Arango::MODE => ArrayMode::*, Arango::COUNTER => ?string, Arango::ITEM_KEY => ?string, Arango::POSITION_KEY => ?string ] ]`.

public array<string|int, mixed> $arrays = []

$fields

The fields definitions to return in get/list methods.

public array<string, mixed> $fields = []

Keys are field names, values are either a Filter constant, a definition array, or null.

Tags
example
$model->fields =>
[
    Schema::ACTIVE                => Filter::BOOL ,
    Schema::WITH_STATUS           => Field::FILTER => Filter::DEFAULT ,
    Schema::ID                    => Filter::ID ,
    Schema::NAME                  => null , // Filter::DEFAULT ,
    Schema::URL                   => Filter::URL ,
    Schema::CREATED               => Filter::DATETIME ,
    Schema::MODIFIED              => [ Field::FILTER => Filter::DATETIME ] ,
    Schema::IMAGE                 => [ Field::FILTER => Filter::EDGE ] ,
    Schema::ALTERNATIVE_HEADLINE  => Filter::TRANSLATE ,
    Schema::ALTERNATE_NAME        => Filter::TRANSLATE ,
    Schema::DESCRIPTION           => Filter::TRANSLATE ,
    Schema::HEADLINE              => Filter::TRANSLATE ,
    Schema::SLOGAN                => Filter::TRANSLATE ,
    Schema::SCOPE_HAS_PERMISSION  => [ Field::FILTER => Filter::BOOL ] ,
    Schema::TOKEN_EXPIRATION      => [ Field::FILTER => Filter::INT  ] ,
    Schema::PERMISSIONS           => [ Field::FILTER => Filter::EDGES , Field::SKINS => [ Skin::FULL ] ]
    Schema::NUM_PERMISSIONS       => Field::FILTER => Filter::EDGES_COUNT
] ;

$purge virtual

The purge mode for this edge collection.

public string|null $purge

One of the constants defined in Purge or null if no purge is configured.

Hooks
public string|null get public set

$skinFields

Optional per-skin alternative projections for the model's own fields.

public array<string, array<string, mixed>> $skinFields = []

A skin => fields table with the exact same semantics as the AQL::SKIN_FIELDS key of an edge/join definition : each bucket is a complete fields array (same shape as $fields), the resolution order is [$skin]['*']$fieldsnull, and the selected bucket fully replaces the others (no merging). An edge/join that declares no projection of its own inherits the target model's buckets, since it prepares the model fields with the request skin.

An empty registry (default) keeps the legacy single-projection behavior, byte-for-byte.

Tags
example
$model->skinFields =
[
    Skin::DEFAULT => [ Schema::NAME => Filter::DEFAULT ] ,
    Skin::FULL    => [ Schema::NAME => Filter::DEFAULT , Schema::ROLES => [ Field::FILTER => Filter::EDGES ] ] ,
] ;

Methods

__construct()

Creates a new Edges instance.

public __construct(Container $container[, array<string|int, mixed> $init = [] ]) : mixed
Parameters
$container : Container

The DI Container reference.

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

The options of the Edges model.

  • 'alters' - An associative array of transformation rules used to alter or enrich the document properties returned by the model.
  • 'binds' - The bindvars array definitions
  • 'collection' - The name of the ArangoDB Document collection to manage
  • 'database' - The arangoDB database reference
  • 'from' - The source Documents model reference (vertex where edges originate).
  • 'to' - The target Documents model reference (vertex where edges point to)
Tags
throws
ContainerExceptionInterface
NotFoundExceptionInterface
DependencyException
NotFoundException
ReflectionException
example
$edges = new Edges( $container,
[
    'collection' => 'user_follows',
    'from'       => $usersModel,
    'to'         => $usersModel,
]);

__destruct()

Invoked when the Edges instance is removed.

public __destruct() : mixed

arrayContains()

Checks whether the array `field` of a single document (identified by `owner`) contains `value`.

public arrayContains([array{owner?: mixed, field?: string, value?: mixed, key?: string, itemKey?: string, prefix?: string, debug?: bool} $init = [] ]) : bool

Generated AQL: RETURN LENGTH( FOR doc IN @@collection FILTER doc._key == @key && POSITION(doc.field, @value) RETURN 1 ) > 0

When the field declares an Arango::ITEM_KEY, value is the key of the element rather than the element itself and the membership test becomes doc.field[? FILTER CURRENT.<itemKey> == @value].

Parameters
$init : array{owner?: mixed, field?: string, value?: mixed, key?: string, itemKey?: string, prefix?: string, debug?: bool} = []
Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
ValidationException
Return values
bool

True if the value is present.

arrayDefaults()

Returns the default seed for the declared embedded array fields: each array field defaults to `[]`, and each declared counter to `0`.

public arrayDefaults() : array<string, array<string|int, mixed>|int>

Used to initialize a freshly created document so that every declared array field is always a real (possibly empty) array — see ensureArrayDefaults().

Return values
array<string, array<string|int, mixed>|int>

e.g. [ 'tracks' => [], 'numberOfTracks' => 0, 'tags' => [] ].

arrayInsert()

Adds one or several values to the array `field` of a single document.

public arrayInsert([array{owner?: mixed, field?: string, value?: mixed, side?: string, mode?: string, key?: string, prefix?: string, touch?: bool, options?: array|object|string|null, debug?: bool} $init = [] ]) : object|null

The uniqueness and sorting are driven by the field's ArrayMode; value may be a scalar or an array (its elements are appended, never nested).

Generated AQL (LIST/SET, side RIGHT): ... UPDATE doc WITH { field: APPEND(doc.field, @value [, true]) [, counter: LENGTH(...)] [, modified: ...] } ...

Parameters
$init : array{owner?: mixed, field?: string, value?: mixed, side?: string, mode?: string, key?: string, prefix?: string, touch?: bool, options?: array|object|string|null, debug?: bool} = []
Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
Throwable
Return values
object|null

The updated document, or null if no document matched.

arrayMove()

Moves an existing `value` to the given zero-based `position` inside the array `field`.

public arrayMove([array{owner?: mixed, field?: string, value?: mixed, position?: int, key?: string, itemKey?: string, prefix?: string, touch?: bool, options?: array|object|string|null, debug?: bool} $init = [] ]) : object|null

Unsupported on a ArrayMode::SORTED_SET field (the sort order overrides any manual position): an UnsupportedOperationException is thrown.

Generated AQL:

LET __rm  = REMOVE_VALUE(doc.field, @value)
LET __arr = APPEND( PUSH( SLICE(__rm, 0, <pos>), @value, true ), SLICE(__rm, <pos>) )
UPDATE doc WITH { field: __arr [, counter: LENGTH(__arr)] [, modified: ...] } ...

When the field declares an Arango::ITEM_KEY, value is the key of the element to move; it is looked up first and the reordering is guarded on it:

LET __el  = FIRST(doc.field[* FILTER CURRENT.<itemKey> == @value])
LET __rm  = doc.field[* FILTER CURRENT.<itemKey> != @value]
LET __arr = __el == null ? doc.field : APPEND( PUSH( SLICE(__rm, 0, <pos>), __el, true ), SLICE(__rm, <pos>) )

A key matching no element therefore leaves the array untouched, rather than inserting a null at the requested position.

Parameters
$init : array{owner?: mixed, field?: string, value?: mixed, position?: int, key?: string, itemKey?: string, prefix?: string, touch?: bool, options?: array|object|string|null, debug?: bool} = []
Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
Throwable
UnsupportedOperationException
ValidationException
Return values
object|null

The updated document, or null if no document matched.

arrayPurgeRef()

Removes a `value` from the array `field` of **every** document of the collection that contains it — typically to purge a now-deleted reference.

public arrayPurgeRef([array{field?: string, value?: mixed, prefix?: string, touch?: bool, count?: bool, options?: array|object|string|null, debug?: bool} $init = [] ]) : array<string|int, object>|int

Generated AQL: FOR doc IN @@collection FILTER POSITION(doc.field, @value) LET __arr = REMOVE_VALUE(doc.field, @value) UPDATE doc WITH { ... } ... RETURN NEW

Unlike the single-document operations, this one is by value only: it ignores any declared Arango::ITEM_KEY and matches the reference structurally.

Parameters
$init : array{field?: string, value?: mixed, prefix?: string, touch?: bool, count?: bool, options?: array|object|string|null, debug?: bool} = []
Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
Throwable
Return values
array<string|int, object>|int

The list of modified documents, or their count when count is true.

arrayRemove()

Removes one or several values from the array `field` of a single document.

public arrayRemove([array{owner?: mixed, field?: string, value?: mixed, key?: string, itemKey?: string, prefix?: string, touch?: bool, options?: array|object|string|null, debug?: bool} $init = [] ]) : object|null

Generated AQL (scalar value): ... UPDATE doc WITH { field: REMOVE_VALUE(doc.field, @value) [, counter: LENGTH(...)] [, modified: ...] } ... (an array value uses REMOVE_VALUES instead).

When the field declares an Arango::ITEM_KEY, value holds the key(s) of the element(s) to drop and the new array is the inline filter doc.field[* FILTER CURRENT.<itemKey> != @value] (NOT IN for a list of keys).

Parameters
$init : array{owner?: mixed, field?: string, value?: mixed, key?: string, itemKey?: string, prefix?: string, touch?: bool, options?: array|object|string|null, debug?: bool} = []
Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
Throwable
ValidationException
Return values
object|null

The updated document, or null if no document matched.

arrayReorder()

Reorders the array `field` from a list of item keys — the whole new order in a single call, where {@see arrayMove()} moves one element at a time.

public arrayReorder([array{owner?: mixed, field?: string, value?: mixed, key?: string, itemKey?: string, prefix?: string, touch?: bool, options?: array|object|string|null, debug?: bool} $init = [] ]) : object|null

Generated AQL:

LET __ord = (FOR __k IN @value LET __el = FIRST(doc.field[* FILTER CURRENT.<itemKey> == __k]) FILTER __el != null RETURN __el)
LET __arr = APPEND(__ord, doc.field[* FILTER CURRENT.<itemKey> NOT IN @value])
UPDATE doc WITH { field: __arr [, counter: LENGTH(__arr)] [, modified: ...] } ...

The elements the list does not mention are kept and appended after it: a partial list reorders what it names instead of deleting the rest. A key matching no element is skipped, and an empty list leaves the array as it is.

Duplicate keys are collapsed (first occurrence wins) before the query is built — resolving the same key twice would otherwise duplicate its element.

Requires an item key, like arrayUpdate(): without an attribute identifying the elements there is nothing to order them by. Unsupported on a ArrayMode::SORTED_SET field, like arrayMove().

Being a permutation of the existing elements, it does not re-apply the field invariant — it cannot introduce a duplicate that was not already there.

Parameters
$init : array{owner?: mixed, field?: string, value?: mixed, key?: string, itemKey?: string, prefix?: string, touch?: bool, options?: array|object|string|null, debug?: bool} = []
Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
Throwable
UnsupportedOperationException
ValidationException
Return values
object|null

The updated document, or null if no document matched.

arrayUpdate()

Merges a partial `patch` into the element of the array `field` carrying the given item key — an **in-place edit**, where the other operations only add, remove or reorder whole elements.

public arrayUpdate([array{owner?: mixed, field?: string, value?: mixed, patch?: array|object, eraseNull?: bool, key?: string, itemKey?: string, prefix?: string, touch?: bool, options?: array|object|string|null, debug?: bool} $init = [] ]) : object|null

Generated AQL:

LET __arr = doc.field[* RETURN CURRENT.<itemKey> == @value ? MERGE(CURRENT, @patch) : CURRENT]
UPDATE doc WITH { field: __arr [, counter: LENGTH(__arr)] [, modified: ...] } ...

Every element is projected back, so a value matching none of them rewrites the array unchanged. The merge is partial: the patch attributes overwrite theirs, the others are kept.

🔑 A null does not erase, unless asked to. MERGE() keeps it: a patch saying { "reason": null } writes the attribute back as null rather than taking it away, so an element rebuilt in place can never lose an attribute it once carried. Pass Arango::ERASE_NULL to read those nulls as erasures instead — the merged element is then wrapped in an UNSET() of their keys:

LET __arr = doc.field[* RETURN CURRENT.<itemKey> == @value ? UNSET(MERGE(CURRENT, @patch), "reason") : CURRENT]

Top-level attributes only, like UNSET() itself: a null sitting inside a sub-object of the patch stays a value. The flag is opt-in, so an existing caller keeps its nulls.

Requires an item key — declared on the field or passed per call. A field targeted by value cannot be edited in place: designating its element would mean holding a byte-for-byte copy of it, which the very patch being applied invalidates, so an UnsupportedOperationException is thrown rather than emitting an operation that only works once.

The field invariant is re-applied afterwards, since a patch can make two elements equal: ArrayMode::SET wraps the result in UNIQUE(), ArrayMode::SORTED_SET in SORTED_UNIQUE().

Parameters
$init : array{owner?: mixed, field?: string, value?: mixed, patch?: array|object, eraseNull?: bool, key?: string, itemKey?: string, prefix?: string, touch?: bool, options?: array|object|string|null, debug?: bool} = []
Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
Throwable
UnsupportedOperationException
ValidationException
Return values
object|null

The updated document, or null if no document matched.

countAnyVertices()

Counts all unique vertices connected in any direction from the given vertex.

public countAnyVertices([string|null $vertex = null ][, array<string|int, mixed> $init = [] ]) : int

This is a convenience method for countVertices(Traversal::ANY, ...). It counts unique neighbors (vertices), not relations (edges).

Parameters
$vertex : string|null = null

Optional '_key' or '_id' of the vertex to start from.

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

Optional query initialization array (e.g., AQL::GRAPH).

Tags
throws
ArangoException
BindException
ConstantException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
Return values
int

The total count of unique connected vertices.

countEdges()

Counts the number of edge documents matching the specified vertices.

public countEdges([string|null $from = null ][, string|null $to = null ][, array<string|int, mixed> $init = [] ]) : int

This counts the relations (edges), not the unique neighbors.

Parameters
$from : string|null = null

Optional '_from' vertex identifier.

$to : string|null = null

Optional '_to' vertex identifier.

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

Optional query options (e.g., AQL::BINDS, operator => Logic::OR).

Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
Return values
int

The total count of matching edge documents.

countInboundVertices()

Counts all unique inbound vertices connected to the given 'to' vertex.

public countInboundVertices([string|null $to = null ][, array<string|int, mixed> $init = [] ]) : int

This is a convenience method for countVertices(Traversal::INBOUND, ...). It counts unique neighbors (vertices), not relations (edges).

Parameters
$to : string|null = null

Optional '_key' or '_id' of the vertex to traverse to.

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

Optional query initialization array (e.g., AQL::GRAPH).

Tags
throws
ArangoException
BindException
ConstantException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
Return values
int

The total count of unique inbound vertices.

countOutboundVertices()

Counts all unique outbound vertices connected from the given 'from' vertex.

public countOutboundVertices([string|null $from = null ][, array<string|int, mixed> $init = [] ]) : int

This is a convenience method for countVertices(Traversal::OUTBOUND, ...). It counts unique neighbors (vertices), not relations (edges).

Parameters
$from : string|null = null

Optional '_key' or '_id' of the vertex to start from.

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

Optional query initialization array (e.g., AQL::GRAPH).

Tags
throws
ArangoException
BindException
ConstantException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
Return values
int

The total count of unique outbound vertices.

countVertices()

Counts all vertices connected with a specific direction.

public countVertices(string $direction[, string|null $vertex = null ][, array{vertexRef?: string, edgeRef?: string|null, pathRef?: string|null, direction?: string, startVertex?: string, graph?: string|null, edgeCollection?: array|string|null, minDepth?: int|null, maxDepth?: int|null, prune?: string|array|null, options?: array|object|string|null, filter?: string|array|null, binds?: array, from?: string|null, to?: string|null, anyRef?: string|null, docRef?: string|null} $init = [] ]) : int

This counts the destination vertex documents.

Parameters
$direction : string

The direction of the relation: Traversal::OUTBOUND, Traversal::INBOUND, or Traversal::ANY.

$vertex : string|null = null

Optional '_key' or '_id' of the vertex to start the relation from.

$init : array{vertexRef?: string, edgeRef?: string|null, pathRef?: string|null, direction?: string, startVertex?: string, graph?: string|null, edgeCollection?: array|string|null, minDepth?: int|null, maxDepth?: int|null, prune?: string|array|null, options?: array|object|string|null, filter?: string|array|null, binds?: array, from?: string|null, to?: string|null, anyRef?: string|null, docRef?: string|null} = []

Optional query initialization and configuration array.

Tags
throws
ArangoException
BindException
ConstantException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
Return values
int

The total count of matching vertices.

deleteEdge()

Delete an edge document connecting two vertices.

public deleteEdge([string|null $from = null ][, string|null $to = null ][, array<string|int, mixed> $init = [] ]) : array<string|int, mixed>|object|null

Builds an AQL query to remove the edge between $from and $to. By default, checks for existing edges to enforce uniqueness (throws Error409) unless disabled via AQL::UNIQUE.

Parameters
$from : string|null = null

The _key or full _id of the source vertex. If only a key is given, it will be resolved using $this->from context.

$to : string|null = null

The _key or full _id of the target vertex. If only a key is given, it will be resolved using $this->to context.

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

Optional array for query options:

  • AQL::UNIQUE (bool) : enforce uniqueness check (default true).
  • AQL::OPTIONS (array): additional options for the underlying ArangoDB INSERT operation.
  • AQL::BINDS, AQL::FILTER, AQL::FIRST, and other options accepted by insert().
Tags
throws
ArangoException

On query execution failure.

BindException

On binding failure.

ContainerExceptionInterface

On container-related errors.

DependencyException

On dependency resolution failure.

NotFoundException

On missing dependencies.

NotFoundExceptionInterface

On missing container entries.

ReflectionException

On reflection errors.

UnsupportedOperationException

If operation is not supported.

Return values
array<string|int, mixed>|object|null

The removed edge document, the first removed edge if multiple exist, or null if none.

deleteEdgeFrom()

Delete all edges where the `_from` vertex matches the given identifier.

public deleteEdgeFrom(string $from[, array<string|int, mixed> $init = [] ]) : array<string|int, mixed>|object|null
Parameters
$from : string

Vertex identifier for the _from field.

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

Optional query options (bind variables, filters, etc.).

Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
UnsupportedOperationException
Return values
array<string|int, mixed>|object|null

Removed edge(s), or null if none found.

deleteEdges()

Delete all edges connected to a specific vertex, either `_from` or `_to`.

public deleteEdges(string|array<string|int, mixed> $vertex[, array<string|int, mixed> $init = [] ]) : array<string|int, mixed>|object|null

Constructs a dynamic AQL query to remove any edge documents where the given vertex is present in _from or _to.

Parameters
$vertex : string|array<string|int, mixed>

The vertex key(s) or full _id(s) to remove from the edge collection.

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

Optional query options:

  • AQL::CONTEXT (Documents|string|AQL::FROM|AQL::TO) : base context for vertex resolution.
  • AQL::BINDS, AQL::FILTER, AQL::DOC_REF etc.
Tags
throws
InvalidArgumentException

If the vertex ID is invalid or empty.

ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
UnsupportedOperationException
Return values
array<string|int, mixed>|object|null

List of removed edge documents, or null if none found.

deleteEdgeTo()

Delete all edges where the `_to` vertex matches the given identifier.

public deleteEdgeTo(string $to[, array<string|int, mixed> $init = [] ]) : array<string|int, mixed>|object|null
Parameters
$to : string

Vertex identifier for the _to field.

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

Optional query options (bind variables, filters, etc.).

Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
UnsupportedOperationException
Return values
array<string|int, mixed>|object|null

Removed edge(s), or null if none found.

diagnose()

Compares everything this model declares with the server state, without touching anything — the read-only half of {@see repair()}.

public diagnose() : array<string|int, DiffReport>

The returned list carries one DiffReport per declared structure object, in dependency order:

  1. the collection (DiffKind::COLLECTION) — existence and type (2 document / 3 edge);
  2. the declared indexes (DiffKind::INDEXES, only when the model declares AQL::INDEXES) — one aggregated report: missing indexes, definition drifts (immutable → drop + recreate required), server indexes that are no longer declared;
  3. the View (DiffKind::VIEW, only when the model declares an AQL::VIEW block) — the SearchTrait::viewDiff() report with its declaration-coherence checks.

A model without a collection resolves to a single DiffStatus::INVALID report; without a database to a single DiffStatus::UNREACHABLE report.

Tags
throws
ReflectionException

When a declared IndexOptions cannot be serialised.

Return values
array<string|int, DiffReport>

One report per declared structure object.

existEdge()

Checks if an edge exists between the given '_from' and '_to' vertices.

public existEdge([string|null $from = null ][, string|null $to = null ][, array<string|int, mixed> $init = [] ]) : bool
Parameters
$from : string|null = null

Optional 'from' vertex unique key identifier.

$to : string|null = null

Optional 'to' vertex unique key identifier.

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

Optional query options, e.g., bind variables.

Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
example
$edges = new Edges($container, ['collection' => 'user_follows']);
$exists = $edges->existEdge('1', '5');
if ($exists) {
    echo "Edge exists between users/1 and posts/5";
}
Return values
bool

True if at least one edge exists, false otherwise.

existEdgeFrom()

Checks if at least one edge exists from the specified 'from' vertex.

public existEdgeFrom(string $from[, array<string|int, mixed> $init = [] ]) : bool
Parameters
$from : string

The 'from' vertex unique key identifier.

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

Optional query options.

Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
example
$edges = new Edges($container, ['collection' => 'user_follows']);
$existsFrom = $edges->existEdgeFrom('1');
if ($existsFrom)
{
    echo "There are edges from users/1";
}
Return values
bool

True if at least one edge exists, false otherwise.

existEdgeTo()

Checks if at least one edge exists to the specified 'to' vertex.

public existEdgeTo(string $to[, array<string|int, mixed> $init = [] ]) : bool
Parameters
$to : string

The 'to' vertex unique key identifier.

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

Optional query options.

Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
example
$edges = new Edges($container, ['collection' => 'user_follows']);
$existsTo = $edges->existEdgeTo('5');
if ($existsTo)
{
    echo "There are edges to posts/5";
}
Return values
bool

True if at least one edge exists, false otherwise.

getAnyVertices()

Retrieves all vertices connected in any direction from the given vertex.

public getAnyVertices([string|null $vertex = null ][, array<string|int, mixed> $init = [] ]) : object|array<string|int, mixed>|null

This method executes an AQL query to fetch vertices that are connected via incoming or outgoing edges to the specified vertex in the current edge collection. It is a convenience wrapper for getVertices() with the direction set to Traversal::ANY.

Note: By default, this method returns raw data unless an AQL::TARGET model is provided in the $init options.

Parameters
$vertex : string|null = null

Optional '_key' or '_id' of the vertex to start from. If null, defaults to the current $this->from vertex reference.

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

Optional array of query options:

  • AQL::ANY_REF (string) : Context for ANY traversal when using a _key (AQL::FROM or AQL::TO). Defaults to AQL::FROM.
  • AQL::DOC_REF (string) : AQL variable name for the vertex (default: 'vertex').
  • AQL::FIRST (bool) : Return only the first matched vertex.
  • AQL::FROM (Documents) : Override the default _from model instance.
  • AQL::GRAPH (string) : The name of a graph to use for traversal.
  • AQL::LIMIT (int) : Maximum number of vertices to return.
  • AQL::MAX_DEPTH (int) : Maximum traversal depth (requires AQL::GRAPH).
  • AQL::MIN_DEPTH (int) : Minimum traversal depth (requires AQL::GRAPH).
  • AQL::OFFSET (int) : Number of vertices to skip.
  • AQL::PRUNE (string|array) : AQL PRUNE condition for graph traversals (requires AQL::GRAPH).
  • AQL::RAW (bool) : Return raw array data. Defaults to true unless AQL::TARGET is specified.
  • AQL::RETURN (string) : Manually specify the AQL RETURN expression.
  • AQL::SORT (string|array) : Sorting criteria.
  • AQL::TARGET (Documents) : Manually specify a Document model for schema mapping.
  • AQL::TO (Documents) : Override the default _to model instance.
  • Additional bind variables can also be passed.
Tags
throws
ArangoException

If there is an error executing the AQL query.

BindException

If a bind variable is missing or invalid.

ConstantException

If the $direction argument is not a valid Traversal constant.

InvalidArgumentException

If the vertex ID is null or empty after processing.

ContainerExceptionInterface

If the DI container fails.

DependencyException

If a dependency is missing in the container.

NotFoundException

If the DI container cannot find a required service.

NotFoundExceptionInterface

Same as above, PSR-11 interface.

ReflectionException

If schema reflection fails.

Example

// $edges = Edges for 'user_follows_user'
$edges = new Edges($container, ['collection' => 'user_follows_user']);

// Get all followers and all followed users for 'users/1'
$allNeighbors = $edges->getAnyVertices('1');
Return values
object|array<string|int, mixed>|null

Returns an array of vertex documents, a single vertex object if AQL::FIRST is true, or null if no vertices found.

getFirstAnyVertex()

Retrieves the first vertex connected in any direction from the given vertex.

public getFirstAnyVertex([string|null $vertex = null ][, array<string|int, mixed> $init = [] ]) : object|array<string|int, mixed>|null

This is a convenience method that wraps getAnyVertices() with the AQL::FIRST flag set to true, returning only the first vertex found in the ANY traversal of the current edge collection.

It executes an AQL query equivalent to:

FOR v IN ANY @vertex @@collection RETURN v

but only returns the first resulting vertex document (if any).

Parameters
$vertex : string|null = null

Optional '_key' or '_id' of the vertex to start from. If null, defaults to the current $this->from vertex reference.

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

Optional query initialization array, merged with [AQL::FIRST => true].

  • AQL::ANY_REF (string) : Context for ANY traversal when using a _key (AQL::FROM or AQL::TO). Defaults to AQL::FROM.
  • AQL::DOC_REF (string) : AQL variable name for the vertex (default: 'vertex').
  • AQL::FROM (Documents) : Override the default _from model instance.
  • AQL::GRAPH (string) : The name of a graph to use for traversal.
  • AQL::LIMIT (int) : Maximum number of vertices to return.
  • AQL::MAX_DEPTH (int) : Maximum traversal depth (requires AQL::GRAPH).
  • AQL::MIN_DEPTH (int) : Minimum traversal depth (requires AQL::GRAPH).
  • AQL::OFFSET (int) : Number of vertices to skip.
  • AQL::PRUNE (string|array) : AQL PRUNE condition for graph traversals (requires AQL::GRAPH).
  • AQL::RAW (bool) : Return raw array data. Defaults to true unless AQL::TARGET is specified.
  • AQL::RETURN (string) : Manually specify the AQL RETURN expression.
  • AQL::SORT (string|array) : Sorting criteria.
  • AQL::TARGET (Documents) : Manually specify a Document model for schema mapping.
  • AQL::TO (Documents) : Override the default _to model instance.
  • Additional bind variables can also be passed.
Tags
throws
ArangoException

If there is an error executing the AQL query.

BindException

If a bind variable is missing or invalid.

ConstantException

If the $direction argument is not a valid Traversal constant.

InvalidArgumentException

If the vertex ID is null or empty after processing.

ContainerExceptionInterface

If the DI container fails.

DependencyException

If a dependency is missing in the container.

NotFoundException

If the DI container cannot find a required service.

NotFoundExceptionInterface

Same as above, PSR-11 interface.

ReflectionException

If schema reflection fails.

Return values
object|array<string|int, mixed>|null

The first vertex document connected to the given vertex, or null if no edge exists.

getFirstInboundVertex()

Retrieves the first inbound vertex connected to the given 'to' vertex.

public getFirstInboundVertex([string|null $to = null ][, array<string|int, mixed> $init = [] ]) : object|array<string|int, mixed>|null

This is a convenience method that wraps getInboundVertices() with the AQL::FIRST flag set to true, returning only the first vertex found in the inbound traversal of the current edge collection.

It executes an AQL query equivalent to:

FOR v IN INBOUND @to @@collection RETURN v

but only returns the first resulting vertex document (if any).

Parameters
$to : string|null = null

Optional '_key' or '_id' of the vertex to traverse to. If null, defaults to the current $this->to vertex reference.

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

Optional query initialization array, merged with [AQL::FIRST => true].

  • AQL::DOC_REF (string) : AQL variable name for the vertex (default: 'vertex').
  • AQL::FROM (Documents) : Override the default _from model instance.
  • AQL::GRAPH (string) : The name of a graph to use for traversal.
  • AQL::LIMIT (int) : Maximum number of vertices to return.
  • AQL::MAX_DEPTH (int) : Maximum traversal depth (requires AQL::GRAPH).
  • AQL::MIN_DEPTH (int) : Minimum traversal depth (requires AQL::GRAPH).
  • AQL::OFFSET (int) : Number of vertices to skip.
  • AQL::PRUNE (string|array) : AQL PRUNE condition for graph traversals (requires AQL::GRAPH).
  • AQL::RAW (bool) : Return raw array data instead of mapped objects.
  • AQL::RETURN (string) : Manually specify the AQL RETURN expression.
  • AQL::SORT (string|array) : Sorting criteria.
  • AQL::TARGET (Documents) : Manually specify a Document model for schema mapping.
  • AQL::TO (Documents) : Override the default _to model instance.
  • Additional bind variables can also be passed.
Tags
throws
ArangoException

If there is an error executing the AQL query.

BindException

If a bind variable is missing or invalid.

ConstantException

If the $direction argument is not a valid Traversal constant.

InvalidArgumentException

If the vertex ID is null or empty after processing.

ContainerExceptionInterface

If the DI container fails.

DependencyException

If a dependency is missing in the container.

NotFoundException

If the DI container cannot find a required service.

NotFoundExceptionInterface

Same as above, PSR-11 interface.

ReflectionException

If schema reflection fails.

Example

// $edges = Edges for 'user_follows_user'
$edges = new Edges($container, ['collection' => 'user_follows_user']);

// Retrieve the first vertex that follows 'users/1' (their first follower)
$firstFollower = $edges->getFirstInboundVertex('users/1');
Return values
object|array<string|int, mixed>|null

The first inbound vertex document connected to the given vertex, or null if no inbound edge exists.

getFirstOutboundVertex()

Retrieves the first outbound vertex connected from the given 'from' vertex.

public getFirstOutboundVertex([string|null $from = null ][, array<string|int, mixed> $init = [] ]) : object|array<string|int, mixed>|null

This is a convenience method that wraps getOutboundVertices() with the AQL::FIRST flag set to true, returning only the first vertex found in the outbound traversal of the current edge collection.

It executes an AQL query equivalent to:

FOR v IN OUTBOUND @from @@collection RETURN v

but only returns the first resulting vertex document (if any).

Parameters
$from : string|null = null

Optional '_key' or '_id' of the vertex to start from. If null, defaults to the current $this->from vertex reference.

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

Optional query initialization array, merged with [AQL::FIRST => true].

  • AQL::DOC_REF (string) : AQL variable name for the vertex (default: 'vertex').
  • AQL::FROM (Documents) : Override the default _from model instance.
  • AQL::GRAPH (string) : The name of a graph to use for traversal.
  • AQL::LIMIT (int) : Maximum number of vertices to return.
  • AQL::MAX_DEPTH (int) : Maximum traversal depth (requires AQL::GRAPH).
  • AQL::MIN_DEPTH (int) : Minimum traversal depth (requires AQL::GRAPH).
  • AQL::OFFSET (int) : Number of vertices to skip.
  • AQL::PRUNE (string|array) : AQL PRUNE condition for graph traversals (requires AQL::GRAPH).
  • AQL::RAW (bool) : Return raw array data instead of mapped objects.
  • AQL::RETURN (string) : Manually specify the AQL RETURN expression.
  • AQL::SORT (string|array) : Sorting criteria.
  • AQL::TARGET (Documents) : Manually specify a Document model for schema mapping.
  • AQL::TO (Documents) : Override the default _to model instance.
  • Additional bind variables can also be passed.
Tags
throws
ArangoException

If there is an error executing the AQL query.

BindException

If a bind variable is missing or invalid.

ConstantException

If the $direction argument is not a valid Traversal constant.

InvalidArgumentException

If the vertex ID is null or empty after processing.

ContainerExceptionInterface

If the DI container fails.

DependencyException

If a dependency is missing in the container.

NotFoundException

If the DI container cannot find a required service.

NotFoundExceptionInterface

Same as above, PSR-11 interface.

ReflectionException

If schema reflection fails.

Example

$edges = new Edges($container, ['collection' => 'user_follows']);

// Retrieve the first vertex that 'users/1' follows
$firstVertex = $edges->getFirstOutboundVertex('users/1');

if ($firstVertex) {
echo "First followed vertex: " . $firstVertex->_id . PHP_EOL;
}
Return values
object|array<string|int, mixed>|null

The first outbound vertex document connected from the given vertex, or null if no outbound edge exists.

getInboundVertices()

Retrieves all inbound vertices connected to the given 'to' vertex.

public getInboundVertices([string|null $to = null ][, array<string|int, mixed> $init = [] ]) : object|array<string|int, mixed>|null

This method executes an AQL query to fetch vertices that are connected via incoming edges to the specified vertex in the current edge collection. It is a convenience wrapper for getVertices() with the direction set to Traversal::INBOUND.

Parameters
$to : string|null = null

Optional '_key' or '_id' of the vertex to traverse to. If null, defaults to the current $this->to vertex reference.

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

Optional array of query options:

  • AQL::DOC_REF (string) : AQL variable name for the vertex (default: 'vertex').
  • AQL::FIRST (bool) : Return only the first matched vertex.
  • AQL::FROM (Documents) : Override the default _from model instance.
  • AQL::GRAPH (string) : The name of a graph to use for traversal.
  • AQL::LIMIT (int) : Maximum number of vertices to return.
  • AQL::MAX_DEPTH (int) : Maximum traversal depth (requires AQL::GRAPH).
  • AQL::MIN_DEPTH (int) : Minimum traversal depth (requires AQL::GRAPH).
  • AQL::OFFSET (int) : Number of vertices to skip.
  • AQL::PRUNE (string|array) : AQL PRUNE condition for graph traversals (requires AQL::GRAPH).
  • AQL::RAW (bool) : Return raw array data instead of mapped objects.
  • AQL::RETURN (string) : Manually specify the AQL RETURN expression.
  • AQL::SORT (string|array) : Sorting criteria.
  • AQL::TARGET (Documents) : Manually specify a Document model for schema mapping (overrides default $from model).
  • AQL::TO (Documents) : Override the default _to model instance.
  • Additional bind variables can also be passed.
Tags
throws
ArangoException

If there is an error executing the AQL query.

BindException

If a bind variable is missing or invalid.

ConstantException

If the $direction argument is not a valid Traversal constant.

InvalidArgumentException

If the vertex ID is null or empty after processing.

ContainerExceptionInterface

If the DI container fails.

DependencyException

If a dependency is missing in the container.

NotFoundException

If the DI container cannot find a required service.

NotFoundExceptionInterface

Same as above, PSR-11 interface.

ReflectionException

If schema reflection fails.

Example

// $edges = Edges for 'user_follows_user'
$edges = new Edges($container, ['collection' => 'user_follows_user']);

// Get all vertices that follow 'users/1' (all followers)
$followers = $edges->getInboundVertices('1');
Return values
object|array<string|int, mixed>|null

Returns an array of vertex documents, a single vertex object if AQL::FIRST is true, or null if no vertices found.

getOutboundVertices()

Retrieves all outbound vertices connected from the given 'from' vertex.

public getOutboundVertices([string|null $from = null ][, array<string|int, mixed> $init = [] ]) : object|array<string|int, mixed>|null

This method executes an AQL query to fetch vertices that are connected via outgoing edges from the specified vertex in the current edge collection. It is a convenience wrapper for getVertices() with the direction set to Traversal::OUTBOUND.

Parameters
$from : string|null = null

Optional '_key' or '_id' of the vertex to start from. If null, defaults to the current $this->from vertex reference.

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

Optional array of query options:

  • AQL::DOC_REF (string) : AQL variable name for the vertex (default: 'vertex').
  • AQL::FIRST (bool) : Return only the first matched vertex.
  • AQL::FROM (Documents) : Override the default _from model instance.
  • AQL::GRAPH (string) : The name of a graph to use for traversal.
  • AQL::LIMIT (int) : Maximum number of vertices to return.
  • AQL::MAX_DEPTH (int) : Maximum traversal depth (requires AQL::GRAPH).
  • AQL::MIN_DEPTH (int) : Minimum traversal depth (requires AQL::GRAPH).
  • AQL::OFFSET (int) : Number of vertices to skip.
  • AQL::PRUNE (string|array) : AQL PRUNE condition for graph traversals (requires AQL::GRAPH).
  • AQL::RAW (bool) : Return raw array data instead of mapped objects.
  • AQL::RETURN (string) : Manually specify the AQL RETURN expression.
  • AQL::SORT (string|array) : Sorting criteria.
  • AQL::TARGET (Documents) : Manually specify a Document model for schema mapping (overrides default $to model).
  • AQL::TO (Documents) : Override the default _to model instance.
  • Additional bind variables can also be passed.
Tags
throws
ArangoException

If there is an error executing the AQL query.

BindException

If a bind variable is missing or invalid.

ConstantException

If the $direction argument is not a valid Traversal constant.

InvalidArgumentException

If the vertex ID is null or empty after processing.

ContainerExceptionInterface

If the DI container fails.

DependencyException

If a dependency is missing in the container.

NotFoundException

If the DI container cannot find a required service.

NotFoundExceptionInterface

Same as above, PSR-11 interface.

ReflectionException

If schema reflection fails.

Example

$edges = new Edges($container, ['collection' => 'user_follows']);

// Get all outbound vertices from 'users/1'
$vertices = $edges->getOutboundVertices('1');

// Get only the first outbound vertex
$firstVertex = $edges->getOutboundVertices('1', [AQL::FIRST => true]);
Return values
object|array<string|int, mixed>|null

Returns an array of vertex documents, a single vertex object if AQL::FIRST is true, or null if no vertices found.

getVertices()

Retrieves all vertices connected with a specific direction.

public getVertices(string $direction[, string|null $vertex = null ][, array<string|int, mixed> $init = [] ]) : object|array<string|int, mixed>|null

This method executes an AQL query to fetch vertices that are connected via edges from the specified vertex in the current edge collection. It supports standard collection traversal (FOR v IN ... @@collection) and named graph traversal (FOR v IN ... GRAPH 'graph_name').

It can optionally return only the first result, or a set of results as an array.

Parameters
$direction : string

The direction of the relation: Traversal::OUTBOUND, Traversal::INBOUND, or Traversal::ANY.

$vertex : string|null = null

Optional '_key' or '_id' of the vertex to start the relation from. If a full '_id' (e.g., "users/123") is provided, it is used directly (assumes vertexID handles this). If only a '_key' (e.g., "123") is provided, it will be prefixed based on context:

  • OUTBOUND: Uses the $from collection.
  • INBOUND: Uses the $to collection.
  • ANY: Uses the $from collection by default (configurable via AQL::ANY_REF).
$init : array<string|int, mixed> = []

Optional array of query options:

  • AQL::ANY_REF (string) : Context for ANY traversal when using a _key (AQL::FROM or AQL::TO). Defaults to AQL::FROM.
  • AQL::DOC_REF (string) : AQL variable name for the vertex (default: 'vertex').
  • AQL::FIRST (bool) : Return only the first matched vertex.
  • AQL::FROM (Documents) : Override the default _from model instance.
  • AQL::GRAPH (string) : The name of a graph to use for traversal (enables graph-specific options).
  • AQL::LIMIT (int) : Maximum number of vertices to return.
  • AQL::MAX_DEPTH (int) : Maximum traversal depth (requires AQL::GRAPH).
  • AQL::MIN_DEPTH (int) : Minimum traversal depth (requires AQL::GRAPH).
  • AQL::OFFSET (int) : Number of vertices to skip (for pagination).
  • AQL::PRUNE (string|array) : AQL PRUNE condition for graph traversals (requires AQL::GRAPH).
  • AQL::RAW (bool) : Return raw array data. Defaults to true for ANY traversals unless AQL::TARGET is specified.
  • AQL::RETURN (string) : Manually specify the AQL RETURN expression (e.g., "v.name"). Overrides model-defined returnFields.
  • AQL::SORT (string|array) : Sorting criteria (e.g., "vertex.name ASC"). Overrides model-defined prepareSort.
  • AQL::TARGET (Documents) : Manually specify a Document model for schema mapping, especially useful for ANY traversals.
  • AQL::TO (Documents) : Override the default _to model instance.
  • Additional bind variables can also be passed.
Tags
throws
ArangoException

If there is an error executing the AQL query.

BindException

If a bind variable is missing or invalid.

ConstantException

If the $direction argument is not a valid Traversal constant.

InvalidArgumentException

If the vertex ID is null or empty after processing.

ContainerExceptionInterface

If the DI container fails.

DependencyException

If a dependency is missing in the container.

NotFoundException

If the DI container cannot find a required service.

NotFoundExceptionInterface

Same as above, PSR-11 interface.

ReflectionException

If schema reflection fails.

example

Assumes $edges collection connects 'users' ($from) to 'groups' ($to)

$edges = new Edges($container, ['collection' => 'user_joins_group']);

Get all outbound vertices (groups) from 'users/1'

$vertices = $edges->getVertices( Traversal::OUTBOUND , '1' ) ;

Get only the first outbound vertex

$firstVertex = $edges->getVertices( Traversal::OUTBOUND , '1' , [AQL::FIRST => true] ) ;

Get all inbound vertices (users) from 'groups/1'

$vertices = $edges->getVertices( Traversal::INBOUND , '1' ) ;

Get all 'any' vertices from 'users/1' (works with a full _id)

$vertices = $edges->getVertices( Traversal::ANY , 'users/1' ) ;

Get 'any' vertices using _key '1'.

$vertices = $edges->getVertices( Traversal::ANY , '1' ) ;

Note : By default, it assumes '1' is a 'user' (AQL::FROM) -> 'users/1'

Force 'any' traversal to use '1' as a 'group' (AQL::TO) -> 'groups/1'

$vertices = $edges->getVertices
(
    Traversal::ANY ,
    '1' ,
    [ AQL::ANY_REF => AQL::TO ]
);

Get outbound vertices using a named graph 'my_graph'

$vertices = $edges->getVertices
(
    Traversal::OUTBOUND ,
    'users/1' ,
    [ AQL::GRAPH => 'my_graph' ]
);

Get raw outbound vertices sorted by name

$vertices = $edges->getVertices
(
    Traversal::OUTBOUND ,
    'users/1' ,
    [ AQL::RAW => true, AQL::SORT => 'vertex.name ASC' ]
);

Permission

When an AQL::TARGET (or a resolved _to/_from) Documents model projects the vertices, its Field::REQUIRES / AQL::REQUIRES gates are enforced: the request authorizer carried in $init[ Arango::AUTHORIZER ] is propagated into the target's returnFields(), so a field or relation hidden from reading stays hidden through the traversal (no field oracle via edges). Fail-open when no authorizer is injected. Only the authorizer is forwarded — the target keeps its own projection defaults.

see
PrepareTraversalTrait
Return values
object|array<string|int, mixed>|null

Returns an array of vertex documents or a single vertex object if AQL::FIRST is true.

hasAnyVertex()

Checks if a specific target vertex is a neighbor in any direction.

public hasAnyVertex(string $source, string $target[, array<string|int, mixed> $init = [] ]) : bool
Parameters
$source : string

The '_key' or '_id' of the vertex to start from.

$target : string

The '_key' or '_id' of the target vertex to check for.

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

Optional array of query options (e.g., AQL::GRAPH).

Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
ConstantException
Return values
bool

True if the target vertex is a neighbor, false otherwise.

hasInboundVertex()

Checks if a specific target vertex is an inbound neighbor of the start vertex.

public hasInboundVertex(string $to, string $from[, array<string|int, mixed> $init = [] ]) : bool
Parameters
$to : string

The '_key' or '_id' of the vertex to traverse to (start vertex).

$from : string

The '_key' or '_id' of the target vertex to check for.

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

Optional array of query options (e.g., AQL::GRAPH).

Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
ConstantException
Return values
bool

True if the target vertex is an inbound neighbor, false otherwise.

hasOutboundVertex()

Checks if a specific target vertex is an outbound neighbor of the start vertex.

public hasOutboundVertex(string $from, string $to[, array<string|int, mixed> $init = [] ]) : bool
Parameters
$from : string

The '_key' or '_id' of the vertex to start from.

$to : string

The '_key' or '_id' of the target vertex to check for.

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

Optional array of query options (e.g., AQL::GRAPH).

Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
ConstantException
Return values
bool

True if the target vertex is an outbound neighbor, false otherwise.

initializeArrays()

Initialize the per-field embedded-array configuration from the `arrays` option.

public initializeArrays([array<string|int, mixed> $init = [] ]) : static

Each entry is either an ArrayMode shorthand ('tags' => ArrayMode::SET) or a richer definition ('tracks' => [ ArrayMode::LIST , Arango::COUNTER => 'numberOfTracks' ]).

Parameters
$init : array<string|int, mixed> = []
Return values
static

initializeDocumentsMethods()

Initialize the Documents HTTP methods signals.

public initializeDocumentsMethods() : static
Return values
static

initializeFields()

Initialize fields definitions from an associative array.

public initializeFields([array<string, mixed> $init = [] ]) : static
Parameters
$init : array<string, mixed> = []

Optional initialization array containing a 'fields' key.

Return values
static

initializeInvalidations()

Connects `afterInsert` / `afterUpdate` / `afterDelete` to the declared services.

public initializeInvalidations(array<string, mixed> $init, ContainerInterface $container) : static

Called at the end of the Documents constructor, AFTER the signals exist — initializeDocumentsMethods() creates them.

The closure resolves each service from the container at EMISSION time, not at boot: a dependent typically depends on this very model, and an eager resolution here would be circular. By the time a write fires the signal, the model is fully built.

Parameters
$init : array<string, mixed>

The model init.

$container : ContainerInterface

The DI container.

Return values
static

initializePurge()

Initialize the purge property from an array or string.

public initializePurge([array<string|int, mixed>|string|null $init = null ]) : static
Parameters
$init : array<string|int, mixed>|string|null = null

If array, looks for the key AQL::PURGE; if string, directly sets the purge mode.

Return values
static

initializeSkinFields()

Initialize the per-skin projections registry from an associative array.

public initializeSkinFields([array<string, mixed> $init = [] ]) : static
Parameters
$init : array<string, mixed> = []

Optional initialization array containing an AQL::SKIN_FIELDS key.

Return values
static

insertEdge()

Inserts a new edge document connecting two vertices, optionally checking for uniqueness.

public insertEdge(string $from, string $to[, array<string|int, mixed> $doc = [] ][, array<string|int, mixed> $init = [] ]) : object|null

Constructs the edge document (_from, _to, attributes) and delegates to the generic insert() method. By default, it first checks if an edge with the same _from and _to already exists using existEdge() and throws an Error409 if found. This behavior can be disabled via the AQL::UNIQUE option.

Parameters
$from : string

The _key or full _id of the source vertex. Resolved using $this->from context if only a key is given.

$to : string

The _key or full _id of the target vertex. Resolved using $this->to context if only a key is given.

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

Optional additional document to complete the edge document (e.g., ['createdAt' => time()]).

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

Optional array for query options:

  • AQL::UNIQUE (bool) : If true (default), checks for an existing edge between $from and $to before inserting. Throws Error409 if found. If false, attempts direct insert (faster, relies on DB index or allows duplicates).
  • AQL::OPTIONS (array): Options passed to the underlying ArangoDB INSERT operation (see InsertOptions).
  • Other options accepted by the underlying insert() method (e.g., AQL::EXCLUDES).
Tags
throws
ArangoException

If the underlying AQL query execution fails.

BindException

If binding variables fails during the insert() process.

ContainerExceptionInterface
DateInvalidTimeZoneException
DateMalformedStringException
DependencyException
Error409

If AQL::UNIQUE is true and an edge already exists between the resolved $from and $to.

NotFoundException
NotFoundExceptionInterface
ReflectionException
UnsupportedOperationException
Throwable
example
$edges = new Edges($container, ['collection' => 'user_follows']);

// Insert, will throw Error409 if edge already exists
try
{
    $newEdge = $edges->insertEdge('users/1', 'users/2', ['since' => date('Y-m-d')]);
    if ($newEdge)
    {
        echo "Edge created with _id: " . $newEdge->_id;
    }
} catch ( Error409 $e )
{
     echo "$e->getMessage() ;
}

// Insert without checking uniqueness
$newEdgeUnchecked = $edges->insertEdge('users/1', 'users/3', [], [ AQL::UNIQUE => false ]);
Return values
object|null

The newly inserted edge document object , or null on failure.

prepareQueryFields()

Prepares query fields based on internal definitions and optional skin filter.

public prepareQueryFields([array<string|int, mixed>|null $fields = null ][, string|null $skin = null ][, string|null $parentKey = null ][, string|array<string|int, mixed>|null $in = null ]) : array<string, array<string|int, mixed>>|null

Converts string filters to array format, applies skins, and normalizes each field. When $fields is null and the model declares a $skinFields registry, the projection is resolved per skin first ([$skin]['*']$fields — the same order as an edge/join AQL::SKIN_FIELDS). The skin filter applies at every nesting level : the sub-fields of a WRAP, DOCUMENT or MAP definition are prepared with the same skin, so a nested Field::SKINS marker is honored in depth. A structural field whose declared sub-fields are all removed by the skin — or whose own AQL::SKIN_FIELDS table resolves to nothing for the requested skin — is dropped from the result.

Parameters
$fields : array<string|int, mixed>|null = null

Optional custom fields to process (defaults to $this->fields).

$skin : string|null = null

Optional skin to filter applicable fields.

$parentKey : string|null = null

Optional parent key definition.

$in : string|array<string|int, mixed>|null = null

Optional field or list of fields to filter the final fields definitions.

Tags
example
$fields = $model->prepareQueryFields('full');
// Returns normalized array of fields including only those matching the 'full' skin
Return values
array<string, array<string|int, mixed>>|null

Normalized fields ready for query, or null if none.

repair()

Reconciles the server with everything this model declares — the acting half of {@see diagnose()}:

public repair([bool $force = false ]) : array<string|int, DiffReport>
  1. a missing collection is created with its declared type and its declared indexes (exactly what the lazy provisioning would do);
  2. missing indexes are created on an existing collection — the case the lazy provisioning never covers; a drifted index is only rebuilt (drop + recreate) when $force is true, because the rebuild opens a window where queries lose the index and a unique index may fail to recreate over duplicated data;
  3. the View is created or resynchronized through SearchTrait::viewSync() (updateProperties(), the View stays queryable while re-indexing).

DiffStatus::INVALID and DiffStatus::UNREACHABLE reports are never acted on; a drifted collection type is never repaired (recreating a collection means losing its documents — that is a migration, not a repair).

Parameters
$force : bool = false

Allow the drop + recreate of drifted indexes.

Tags
throws
ReflectionException

When a declared IndexOptions cannot be serialised.

Return values
array<string|int, DiffReport>

The diagnose() reports, with $applied set on every object actually created or updated.

returnFields()

Generates an AQL document expression or LET statement with the selected fields.

public returnFields([array<string, mixed> $init = [] ][, array<string|int, mixed> &$variables = [] ][, bool $isVariable = false ]) : string

Supports edges, joins, skins, and query fields.

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

Options to customize the query:

  • string|array $fields: comma-separated list or array of field names
  • ?array $queryFields: prepared query fields (overrides internal $fields)
  • ?string $lang: optional language key
  • string $docRef: document reference name
  • bool $isResult: whether to assign to result variable
$variables : array<string|int, mixed> = []
$isVariable : bool = false

Whether to generate a LET statement instead of RETURN

Tags
throws
ContainerExceptionInterface
NotFoundExceptionInterface
Exception
example
$aql = $model->returnFields
([
    Arango::QUERY_FIELDS => $queryFields,
    Arango::DOC_REF      => 'doc',
    Arango::SKIN         => 'full'
]);
Return values
string

Compiled AQL query fragment

arrayCounter()

Returns the configured length-counter attribute of an array field, or null.

protected arrayCounter(string|null $field) : string|null
Parameters
$field : string|null
Return values
string|null

arrayItemKey()

Resolves the item-key attribute of an array field — the attribute carried by each element that identifies it — honouring an optional per-call `itemKey` override, then the declared configuration, then defaulting to null.

protected arrayItemKey(string|null $field[, array<string|int, mixed> $init = [] ]) : string|null

A null result means the field is targeted by value (the historical behaviour); a non-null one switches the element-level operations to a key match.

The resolved name is interpolated verbatim into the generated AQL (the array expansion helpers do no escaping), so it is validated here — whatever its origin — against assertAttributeName().

Parameters
$field : string|null
$init : array<string|int, mixed> = []
Tags
throws
ValidationException

When the configured item key is not a safe attribute name.

Return values
string|null

The validated item-key attribute, or null when the field is targeted by value.

arrayMode()

Resolves the {@see ArrayMode} of an array field, honouring an optional per-call `mode` override, then the declared configuration, then defaulting to LIST.

protected arrayMode(string|null $field[, array<string|int, mixed> $init = [] ]) : string
Parameters
$field : string|null
$init : array<string|int, mixed> = []
Return values
string

arrayPositionKey()

Resolves the position-key attribute of an array field — the attribute of each element carrying its rank — honouring an optional per-call `positionKey` override, then the declared configuration, then defaulting to null.

protected arrayPositionKey(string|null $field[, array<string|int, mixed> $init = [] ]) : string|null

A null result means the field is never renumbered (the historical behaviour); a non-null one makes every write rewrite that attribute from the element indices.

The resolved name is interpolated verbatim into the generated AQL, so it is validated here — whatever its origin — against assertAttributeName(). It is additionally required to be a flat name: unlike an item key, which is only ever read, a position key is written back, and a dotted path would produce a single attribute literally named meta.position instead of a nested one.

Parameters
$field : string|null
$init : array<string|int, mixed> = []
Tags
throws
ValidationException

When the configured position key is not a safe flat attribute name.

Return values
string|null

The validated position-key attribute, or null when the field is not renumbered.

arrayWith()

Builds the `WITH { ... }` object clause: the array field, its optional length counter, and the `modified` timestamp unless `touch` is disabled.

protected arrayWith(string|null $field, string $arrayVar[, array<string|int, mixed> $init = [] ]) : string
Parameters
$field : string|null

The array attribute name.

$arrayVar : string

The AQL variable holding the new array (see self::ARRAY_VAR).

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

countEdgesQuery()

Generates the count query and fill the binds array reference.

protected countEdgesQuery([string|null $from = null ][, string|null $to = null ][, array<string|int, mixed> &$binds = [] ][, array<string|int, mixed> $init = [] ]) : string
Parameters
$from : string|null = null

The from vertex identifier

$to : string|null = null

The to vertex identifier

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

The bindVars array reference.

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

The option of the method.

  • 'collection' : The name of the collection, by default use the $this->collection property.
  • 'name' : The name of the bindVariable collection, by default use the @@collection.
  • 'operator' : Indicates if the filter of the vertices use a Logic::AND or Logic::OR operator (default Logic::AND)
  • 'variableName' : The name of the document in the query (default 'doc') AQL::DOC_REF
Tags
throws
BindException
ReflectionException
example
[ $query , $binds ] = $this->countEdgeQuery( $from , $to ) ;
Return values
string

The AQL query expression.

ensureArrayDefaults()

Builds an `ensure` closure that seeds the declared array fields to `[]` (and their counters to `0`) for any missing key of a document being created, then applies the optional user-supplied `ensure`. Returns the user closure unchanged when no array field is declared (so models without `AQL::ARRAYS` are untouched).

protected ensureArrayDefaults([Closure|null $ensure = null ]) : Closure|null
Parameters
$ensure : Closure|null = null

An optional user ensure closure to compose with.

Return values
Closure|null

arrayErasedKeys()

The attributes a patch asks to be taken away — the keys it carries at null.

private arrayErasedKeys(mixed $patch) : array<int, string>

Only the top level is read, like AQL UNSET() itself: a null sitting inside a sub-object of the patch is a value, not an erasure. An element loses one whole attribute at a time, never half of one.

🚨 The names are interpolated verbatim into the generated AQL — UNSET() takes string literals, not binds — so each one goes through the same guard as every other attribute name this trait emits. A patch carrying an integer key (a list cast to an object) names no attribute and is skipped.

Parameters
$patch : mixed

The patch handed to self::arrayUpdate().

Tags
throws
ValidationException

When a key is not a safe flat attribute name.

Return values
array<int, string>

The attribute names to remove, possibly empty.

arrayRank()

Appends the renumbering `LET` to the given clauses when the field declares an {@see Arango::POSITION_KEY}, and returns them along with the AQL variable holding the array to write back.

private arrayRank(string|null $field, array<string|int, mixed> $lets, array<string|int, mixed> $init) : array{0: array, 1: string}

Generated AQL:

LET __pos = LENGTH(__arr) == 0 ? [] : (FOR __i IN 0 .. LENGTH(__arr) - 1 RETURN MERGE(NTH(__arr,__i),{ position: __i }))

It always runs last, on the array every operation has already produced: the field invariant is therefore applied before the ranks, which matters on a ArrayMode::SET — renumbering makes every element distinct, so a UNIQUE() running after it would no longer collapse anything. For the same reason, a patch carrying the position attribute loses against the renumbering.

The empty-array branch is not cosmetic: 0 .. LENGTH(__arr) - 1 becomes 0 .. -1 on an empty array, which AQL reads as a descending range and expands to [0, -1] — two phantom elements would be ranked into the document.

Shared by runArrayUpdate() and arrayPurgeRef(), which compiles its own collection-wide query: a purge would otherwise leave gaps in the numbering.

Parameters
$field : string|null

The array attribute name.

$lets : array<string|int, mixed>

The clauses produced by the operation, ending with self::ARRAY_VAR.

$init : array<string|int, mixed>
Tags
throws
ReflectionException
UnsupportedOperationException

On a sortedSet field (the ranks would feed the sort back).

ValidationException

When the configured position key is not a safe flat attribute name.

Return values
array{0: array, 1: string}

The clauses, and the variable holding the array to write.

filterFieldsBySkin()

Filters fields based on an optional skin.

private filterFieldsBySkin(array<string, mixed> $fields, string|null $skin) : array<string, mixed>
Parameters
$fields : array<string, mixed>

Fields to filter

$skin : string|null

Skin to match

Return values
array<string, mixed>

Filtered fields

generateUniqueKey()

Generates a unique key for special filters like edges, joins, or unique names.

private generateUniqueKey(string $key, string|null $filter[, string|null $parentKey = null ]) : string|null
Parameters
$key : string

Base field key

$filter : string|null

Filter type

$parentKey : string|null = null

Optional parent key.

Return values
string|null

Generated unique key or existing

hasVertex()

Private helper to check for vertex existence in a specific direction.

private hasVertex(string $direction, string $startVertex, string $targetVertex[, array<string|int, mixed> $init = [] ]) : bool

This method builds the filter query to check if a $targetVertex exists in the results of a traversal from $startVertex.

Parameters
$direction : string

Traversal::OUTBOUND, Traversal::INBOUND, or Traversal::ANY

$startVertex : string

The _key or _id of the vertex to start from.

$targetVertex : string

The _key or _id of the vertex to find.

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

Optional query options.

Tags
throws
ArangoException
BindException
ConstantException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
Return values
bool

normalizeFieldDefinition()

Normalize a field definition into a structured array for queries.

private normalizeFieldDefinition(string $key[, array<string|int, mixed> $options = [] ][, string|null $parentKey = null ][, string|null $skin = null ]) : array<string, mixed>|null
  • Converts string filters to array
  • Handles subfields for DOCUMENT or MAP filters
  • Generates unique keys for special filters

The sub-fields of a structural filter (WRAP, DOCUMENT, MAP) are prepared recursively with the SAME skin, so a Field::SKINS marker on a nested sub-field is honored at every depth — with the level-one rules: a sub-field without a marker is always kept, and a null skin keeps everything. When the skin filters out ALL the declared sub-fields, the method returns null and the field itself is dropped from the projection (key absent).

A structural field can also declare per-skin alternative sub-projections through AQL::SKIN_FIELDS (same table shape and resolution order as an edge/join definition). A declared table that resolves to nothing for the requested skin drops the field the same way (returns null).

Parameters
$key : string

Field name

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

Field options, may include:

  • Field::FILTER
  • Field::NAME
  • Field::QUOTED
  • Field::FIELDS (for DOCUMENT or MAP)
$parentKey : string|null = null

The Optional parent key

$skin : string|null = null

Optional skin propagated to the nested sub-fields.

Tags
example
$normalized = $this->normalizeFieldDefinition( 'permissions',
[
    Field::FILTER => Filter::EDGES,
    Field::SKINS => [Skin::FULL]
]);
Return values
array<string, mixed>|null

Normalized field definition, or null when the skin removed every declared sub-field.

runArrayUpdate()

Compiles and executes a single-document array UPDATE (`FOR ... FILTER ... LET ... UPDATE ... RETURN NEW`), emitting the update signals around the write.

private runArrayUpdate(string|null $field, array<string|int, mixed> $lets, string $filter, array<string|int, mixed> &$binds, array<string|int, mixed> $init) : object|null
Parameters
$field : string|null

The array attribute name.

$lets : array<string|int, mixed>

The ordered LET clauses producing the self::ARRAY_VAR variable.

$filter : string

The FILTER predicate locating the document.

$binds : array<string|int, mixed>

The bind variables (mutated by reference).

$init : array<string|int, mixed>
Tags
throws
ArangoException
BindException
ContainerExceptionInterface
DependencyException
NotFoundException
NotFoundExceptionInterface
ReflectionException
Throwable
Return values
object|null
On this page

Search results