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 (
fromandto). - Counting edges based on vertex filters.
- AQL query generation for counting edges with bind variables.
Tags
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.
Properties
- $arrays : array<string|int, mixed>
- The per-field embedded-array configuration, normalised to `[ field => [ Arango::MODE => ArrayMode::*, Arango::COUNTER => ?string ] ]`.
- $fields : array<string, mixed>
- The fields definitions to return in get/list methods.
- $purge : string|null
- The purge mode for this edge collection.
- $_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.
- 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.
- initializePurge() : static
- Initialize the purge property from an array or string.
- 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.
- 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.
- 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).
- 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>
- 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'
Properties
$arrays
The per-field embedded-array configuration, normalised to `[ field => [ Arango::MODE => ArrayMode::*, Arango::COUNTER => ?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
$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
$_purge
private
string|null
$_purge
= null
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
__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, 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
Parameters
- $init : array{owner?: mixed, field?: string, value?: mixed, key?: string, prefix?: string, debug?: bool} = []
Tags
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
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, 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: ...] } ...
Parameters
- $init : array{owner?: mixed, field?: string, value?: mixed, position?: int, key?: string, prefix?: string, touch?: bool, options?: array|object|string|null, debug?: bool} = []
Tags
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
Parameters
- $init : array{field?: string, value?: mixed, prefix?: string, touch?: bool, count?: bool, options?: array|object|string|null, debug?: bool} = []
Tags
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, 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).
Parameters
- $init : array{owner?: mixed, field?: string, value?: mixed, key?: string, prefix?: string, touch?: bool, options?: array|object|string|null, debug?: bool} = []
Tags
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
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
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
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
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
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
_keyor full_idof the source vertex. If only a key is given, it will be resolved using$this->fromcontext. - $to : string|null = null
-
The
_keyor full_idof the target vertex. If only a key is given, it will be resolved using$this->tocontext. - $init : array<string|int, mixed> = []
-
Optional array for query options:
AQL::UNIQUE(bool) : enforce uniqueness check (defaulttrue).AQL::OPTIONS(array): additional options for the underlying ArangoDBINSERToperation.AQL::BINDS,AQL::FILTER,AQL::FIRST, and other options accepted byinsert().
Tags
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
_fromfield. - $init : array<string|int, mixed> = []
-
Optional query options (bind variables, filters, etc.).
Tags
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_REFetc.
Tags
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
_tofield. - $init : array<string|int, mixed> = []
-
Optional query options (bind variables, filters, etc.).
Tags
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:
- the collection (DiffKind::COLLECTION) — existence and
type (
2document /3edge); - 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; - the View (DiffKind::VIEW, only when the model declares
an
AQL::VIEWblock) — 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
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
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
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
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->fromvertex reference. - $init : array<string|int, mixed> = []
-
Optional array of query options:
- AQL::ANY_REF (string) : Context for
ANYtraversal when using a_key(AQL::FROMorAQL::TO). Defaults toAQL::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
_frommodel 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
PRUNEcondition for graph traversals (requiresAQL::GRAPH). - AQL::RAW (bool) : Return raw array data. Defaults to
trueunlessAQL::TARGETis specified. - AQL::RETURN (string) : Manually specify the AQL
RETURNexpression. - AQL::SORT (string|array) : Sorting criteria.
- AQL::TARGET (Documents) : Manually specify a Document model for schema mapping.
- AQL::TO (Documents) : Override the default
_tomodel instance. - Additional bind variables can also be passed.
- AQL::ANY_REF (string) : Context for
Tags
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->fromvertex reference. - $init : array<string|int, mixed> = []
-
Optional query initialization array, merged with
[AQL::FIRST => true].- AQL::ANY_REF (string) : Context for
ANYtraversal when using a_key(AQL::FROMorAQL::TO). Defaults toAQL::FROM. - AQL::DOC_REF (string) : AQL variable name for the vertex (default: 'vertex').
- AQL::FROM (Documents) : Override the default
_frommodel 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
PRUNEcondition for graph traversals (requiresAQL::GRAPH). - AQL::RAW (bool) : Return raw array data. Defaults to
trueunlessAQL::TARGETis specified. - AQL::RETURN (string) : Manually specify the AQL
RETURNexpression. - AQL::SORT (string|array) : Sorting criteria.
- AQL::TARGET (Documents) : Manually specify a Document model for schema mapping.
- AQL::TO (Documents) : Override the default
_tomodel instance. - Additional bind variables can also be passed.
- AQL::ANY_REF (string) : Context for
Tags
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->tovertex 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
_frommodel 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
PRUNEcondition for graph traversals (requiresAQL::GRAPH). - AQL::RAW (bool) : Return raw array data instead of mapped objects.
- AQL::RETURN (string) : Manually specify the AQL
RETURNexpression. - AQL::SORT (string|array) : Sorting criteria.
- AQL::TARGET (Documents) : Manually specify a Document model for schema mapping.
- AQL::TO (Documents) : Override the default
_tomodel instance. - Additional bind variables can also be passed.
Tags
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->fromvertex 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
_frommodel 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
PRUNEcondition for graph traversals (requiresAQL::GRAPH). - AQL::RAW (bool) : Return raw array data instead of mapped objects.
- AQL::RETURN (string) : Manually specify the AQL
RETURNexpression. - AQL::SORT (string|array) : Sorting criteria.
- AQL::TARGET (Documents) : Manually specify a Document model for schema mapping.
- AQL::TO (Documents) : Override the default
_tomodel instance. - Additional bind variables can also be passed.
Tags
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->tovertex 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
_frommodel 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
PRUNEcondition for graph traversals (requiresAQL::GRAPH). - AQL::RAW (bool) : Return raw array data instead of mapped objects.
- AQL::RETURN (string) : Manually specify the AQL
RETURNexpression. - AQL::SORT (string|array) : Sorting criteria.
- AQL::TARGET (Documents) : Manually specify a Document model for schema mapping (overrides default
$frommodel). - AQL::TO (Documents) : Override the default
_tomodel instance. - Additional bind variables can also be passed.
Tags
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->fromvertex 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
_frommodel 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
PRUNEcondition for graph traversals (requiresAQL::GRAPH). - AQL::RAW (bool) : Return raw array data instead of mapped objects.
- AQL::RETURN (string) : Manually specify the AQL
RETURNexpression. - AQL::SORT (string|array) : Sorting criteria.
- AQL::TARGET (Documents) : Manually specify a Document model for schema mapping (overrides default
$tomodel). - AQL::TO (Documents) : Override the default
_tomodel instance. - Additional bind variables can also be passed.
Tags
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$fromcollection.INBOUND: Uses the$tocollection.ANY: Uses the$fromcollection by default (configurable viaAQL::ANY_REF).
- $init : array<string|int, mixed> = []
-
Optional array of query options:
- AQL::ANY_REF (string) : Context for
ANYtraversal when using a_key(AQL::FROMorAQL::TO). Defaults toAQL::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
_frommodel 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
PRUNEcondition for graph traversals (requiresAQL::GRAPH). - AQL::RAW (bool) : Return raw array data. Defaults to
trueforANYtraversals unlessAQL::TARGETis specified. - AQL::RETURN (string) : Manually specify the AQL
RETURNexpression (e.g.,"v.name"). Overrides model-definedreturnFields. - AQL::SORT (string|array) : Sorting criteria (e.g.,
"vertex.name ASC"). Overrides model-definedprepareSort. - AQL::TARGET (Documents) : Manually specify a Document model for schema mapping, especially useful for
ANYtraversals. - AQL::TO (Documents) : Override the default
_tomodel instance. - Additional bind variables can also be passed.
- AQL::ANY_REF (string) : Context for
Tags
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
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
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
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
staticinitializeDocumentsMethods()
Initialize the Documents HTTP methods signals.
public
initializeDocumentsMethods() : static
Return values
staticinitializeFields()
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
staticinitializePurge()
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
staticinsertEdge()
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
_keyor full_idof the source vertex. Resolved using$this->fromcontext if only a key is given. - $to : string
-
The
_keyor full_idof the target vertex. Resolved using$this->tocontext 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$fromand$tobefore inserting. ThrowsError409if found. Iffalse, attempts direct insert (faster, relies on DB index or allows duplicates). - AQL::OPTIONS (array): Options passed to the underlying ArangoDB
INSERToperation (see InsertOptions). - Other options accepted by the underlying
insert()method (e.g.,AQL::EXCLUDES).
- AQL::UNIQUE (bool) : If
Tags
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.
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
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>
- a missing collection is created with its declared type and its declared indexes (exactly what the lazy provisioning would do);
- missing indexes are created on an existing collection — the
case the lazy provisioning never covers; a drifted index is only
rebuilt (drop + recreate) when
$forceis true, because the rebuild opens a window where queries lose the index and a unique index may fail to recreate over duplicated data; - 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
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
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|nullarrayMode()
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
stringarrayWith()
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 (e.g. '__arr').
- $init : array<string|int, mixed> = []
Return values
stringcountEdgesQuery()
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
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|nullfilterFieldsBySkin()
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
Return values
boolnormalizeFieldDefinition()
Normalize a field definition into a structured array for queries.
private
normalizeFieldDefinition(string $key[, array<string|int, mixed> $options = [] ][, string|null $parentKey = null ]) : array<string, mixed>
- Converts string filters to array
- Handles subfields for DOCUMENT or MAP filters
- Generates unique keys for special filters
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
Tags
Return values
array<string, mixed> —Normalized field definition
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
__arrvariable. - $filter : string
-
The FILTER predicate locating the document.
- $binds : array<string|int, mixed>
-
The bind variables (mutated by reference).
- $init : array<string|int, mixed>