EdgesToTrait uses trait:short
Provides utilities for initialize edge `to` vertex references in ArangoDB edge queries.
This trait manages the source ('to') vertex models for edge collections. It allows initializing these references from arrays or PSR-11.
Tags
Table of Contents
Constants
- ON_DELETE_VERTEX : string = 'onDeleteVertex'
- Constant for the method name to hook deletion events.
Properties
Methods
- initializeTo() : static
- Initialize the 'to' reference.
- onDeleteVertex() : void
- Invoked when a vertex document is deleted.
- registerTo() : $this
- Register the `to` Documents signals.
- releaseTo() : static
- Release the 'to' reference.
- unregisterTo() : $this
- Unregister the `to` Documents signals.
- purgeVertices() : void
- Purge related vertex documents based on the defined purge direction.
Constants
ON_DELETE_VERTEX
Constant for the method name to hook deletion events.
public
string
ON_DELETE_VERTEX
= 'onDeleteVertex'
Properties
$to
The target document collection model (vertex where edges point to).
public
Documents|null
$to
= null
Methods
initializeTo()
Initialize the 'to' reference.
public
initializeTo([array<string|int, mixed>|string|Documents|null $init = null ][, ContainerInterface|null $container = null ]) : static
The target document collection (vertex where edges point to).
Parameters
- $init : array<string|int, mixed>|string|Documents|null = null
-
Can be :
- an associative array containing AQL::FROM key,
- a string service identifier (for PSR-11 container),
- a Documents instance,
- or null.
- $container : ContainerInterface|null = null
Tags
Return values
staticonDeleteVertex()
Invoked when a vertex document is deleted.
public
onDeleteVertex(Payload $payload) : void
This method :
- Deletes all edges of the specific document resource ;
- Determinates which related vertex documents to purge based on the
$purgeproperty ;
Parameters
- $payload : Payload
-
The payload containing:
data: The deleted vertex or array of vertices.target: The vertex model (fromorto) from which deletion originates.
Tags
registerTo()
Register the `to` Documents signals.
public
registerTo() : $this
Return values
$thisreleaseTo()
Release the 'to' reference.
public
releaseTo() : static
Return values
staticunregisterTo()
Unregister the `to` Documents signals.
public
unregisterTo() : $this
Return values
$thispurgeVertices()
Purge related vertex documents based on the defined purge direction.
private
purgeVertices(array<string|int, mixed> $edges, object $target) : void
This method is automatically called by onDeleteVertex() after an edge's vertex has been deleted.
Usage
For example, suppose you have a WebAPI document connected to several Permission documents via edges.
If you delete the WebAPI document and the purge mode is set to Purge::OUTBOUND or Purge::BOTH,
all connected Permission vertices in their collection will be automatically removed.
Similarly, if a Permission vertex is deleted and the purge mode is Purge::INBOUND or Purge::BOTH,
the related WebAPI vertices will be deleted according to the purge direction.
Graph illustration of purge directions
OUTBOUND (delete TO when FROM is deleted): [FROM: WebAPI] ---> [TO: Permission] DELETE WebAPI -> automatically DELETE Permission(s)
INBOUND (delete FROM when TO is deleted): [FROM: WebAPI] ---> [TO: Permission] DELETE Permission -> automatically DELETE WebAPI
BOTH (delete both sides): [FROM: WebAPI] ---> [TO: Permission] DELETE WebAPI -> DELETE Permission DELETE Permission -> DELETE WebAPI
Parameters
- $edges : array<string|int, mixed>
-
Array of edge documents returned by deleteEdges().
- $target : object
-
The vertex model that triggered the deletion.
Return values
void —Example:
$edges = $edge->deleteEdges(vertex: $vertexKeys, init: [AQL::CONTEXT => $edge->from]);
$edge->purgeVertices($edges, $edge->from);