OnUpdateRelations uses trait:short, trait:short, trait:short
Table of Contents
Constants
- ON_UPDATE_RELATIONS : string = 'onUpdateRelations'
- The 'onUpdateRelations' method name.
Methods
- insert() : object|null
- Insert a new document into the collection.
- onUpdateRelations() : void
- Invoked when a document is inserted, replaced or updated in a Documents to update the document's relations (edges).
- registerUpdateRelations() : static
- Register the onUpdateRelations callbacks to handles the insert/replace/update methods.
- replace() : object|null
- Replaces an existing document in a collection with a new one.
- unregisterUpdateRelations() : static
- Unregister the onUpdateRelations callbacks.
- update() : object|null
- Partially updates a document in the collection.
- updateDate() : object|null
- Update a single date property in a document with the current date .
- executeWriteOperation() : object|null
- The main internal function to update or replace a document in a collection.
Constants
ON_UPDATE_RELATIONS
The 'onUpdateRelations' method name.
public
string
ON_UPDATE_RELATIONS
= 'onUpdateRelations'
Methods
insert()
Insert a new document into the collection.
public
insert([array{binds?: array|null, conditions?: array|null, debug?: bool|null, doc?: null|array|object|string, excludes?: array|null} $init = [] ]) : object|null
Parameters
- $init : array{binds?: array|null, conditions?: array|null, debug?: bool|null, doc?: null|array|object|string, excludes?: array|null} = []
-
The parameters to passed-in the function.
- doc : The document to insert in the collection.
- excludes : The list of all attributes to excludes in the new document
- binds The default variables to binds.
- relations The edges relations definitions to link after the insertion
Tags
Return values
object|nullonUpdateRelations()
Invoked when a document is inserted, replaced or updated in a Documents to update the document's relations (edges).
public
onUpdateRelations(Payload $payload) : void
Parameters
- $payload : Payload
-
The payload notice.
Tags
registerUpdateRelations()
Register the onUpdateRelations callbacks to handles the insert/replace/update methods.
public
registerUpdateRelations() : static
Return values
staticreplace()
Replaces an existing document in a collection with a new one.
public
replace([array{doc?: array|object|null, key?: string|null, value?: mixed, binds?: array|null, excludes?: string[]|null, options?: array|string|object|null, prefix?: string|null, return?: string|null} $init = [] ]) : object|null
This operation removes all existing attributes of the document, except immutable system attributes
(such as _key, _id, _rev), and sets the given attributes provided in $doc.
It uses an AQL query similar to:
FOR doc IN @@collection
FILTER doc._key == @key
REPLACE { ...fillableDocument, modified: DATE_ISO8601(DATE_NOW()) } IN @@collection
RETURN NEW
Example usage:
$result = $this->replace
([
Arango::DOC => [ 'name' => 'Marc', 'city' => 'Marseille' ],
Arango::VALUE => '2531394',
Arango::BINDS => [ '@collection' => 'places' ],
]);
echo $result->name; // "Marc"
Parameters
- $init : array{doc?: array|object|null, key?: string|null, value?: mixed, binds?: array|null, excludes?: string[]|null, options?: array|string|object|null, prefix?: string|null, return?: string|null} = []
-
The initialization options for the REPLACE operation.
Tags
Return values
object|null —The replaced document, or null if no matching document was found.
unregisterUpdateRelations()
Unregister the onUpdateRelations callbacks.
public
unregisterUpdateRelations() : static
Return values
staticupdate()
Partially updates a document in the collection.
public
update([array{doc?: array|object|null, key?: string|null, excludes?: string[]|null, value?: mixed, prefix?: string|null, binds?: array|null, options?: array|string|object|null, return?: string|null} $init = [] ]) : object|null
This method generates and executes an AQL UPDATE operation on the targeted document.
Only the attributes specified in the doc array or object are modified; any other
attributes in the existing document remain unchanged. Immutable system attributes
(such as _key, _id, _rev) are never overwritten.
AQL Syntax
// Update using a key:
UPDATE @key WITH { ...updatedAttributes } IN @@collection [OPTIONS {...}]
// Update using a FOR ... FILTER clause:
FOR doc IN @@collection
FILTER doc._key == @key
UPDATE doc WITH { ...updatedAttributes } IN @@collection [OPTIONS {...}]
RETURN NEW
Initialization Options ($init)
Parameters
- $init : array{doc?: array|object|null, key?: string|null, excludes?: string[]|null, value?: mixed, prefix?: string|null, binds?: array|null, options?: array|string|object|null, return?: string|null} = []
-
Examples*
// 1. Update a document by key: $result = $this->update ([ Arango::DOC => [ 'name' => 'Marc' ], Arango::VALUE => '2531394', Arango::BINDS => [ '@collection' => 'places' ] ]); // 2. Update excluding certain fields: $result = $this->update ([ Arango::DOC => [ 'name' => 'Marc', 'created' => '...' ], Arango::EXCLUDES => [ 'created' ], Arango::VALUE => '2531394' ]); // 3. Update and return the OLD document: $result = $this->update ([ Arango::DOC => [ 'name' => 'Marc' ], Arango::VALUE => '2531394', Arango::RETURN => Clause::OLD ]);
Tags
Return values
object|null —The updated document, or null if no document matched the key.
updateDate()
Update a single date property in a document with the current date .
public
updateDate([array<string|int, mixed> $init = [] ][, string $property = Schema::MODIFIED ]) : object|null
By default, it updates the modified property with the current timestamp.
Parameters
- $init : array<string|int, mixed> = []
-
Additional options like binds, return clause, etc.
- $property : string = Schema::MODIFIED
-
The document property to update (default: Schema::MODIFIED).
Tags
Return values
object|null —The updated document.
executeWriteOperation()
The main internal function to update or replace a document in a collection.
protected
executeWriteOperation(array{value?: mixed|null, doc?: array|object|string|null, key?: string|null, prefix?: string|null, binds?: array|null, excludes?: string[]|null, options?: array|string|object|null, return?: string|null, debug?: bool|null} $init[, string $operation = Operation::UPDATE ]) : object|null
This method builds and executes an AQL UPDATE or REPLACE query for a given document.
It supports bind variables, exclusion of certain fields, custom options, and returning
either the NEW or OLD document after the operation.
Supported $init options*
Parameters
- $init : array{value?: mixed|null, doc?: array|object|string|null, key?: string|null, prefix?: string|null, binds?: array|null, excludes?: string[]|null, options?: array|string|object|null, return?: string|null, debug?: bool|null}
- $operation : string = Operation::UPDATE
-
The type of operation:
Operation::UPDATEorOperation::REPLACE.
Tags
Return values
object|null —Returns the updated or replaced document, or null if no matching document was found.