Oihana PHP Arango

sortEdgeVariable.php

Table of Contents

Functions

sortEdgeVariable()  : string
Generates the internal AQL 'SORT' clause for an edge variable subquery.

Functions

sortEdgeVariable()

Generates the internal AQL 'SORT' clause for an edge variable subquery.

sortEdgeVariable(array<string|int, mixed>|string|null $definition[, string $vertexRef = AQL::VERTEX ][, string $edgeRef = AQL::EDGE ][, string $defaultProperty = Schema::CREATED ]) : string

This helper method interprets a flexible sort definition and constructs the appropriate AQL 'SORT' expression.

  • If $definition is an array: Looks for AQL::SORT (property) and AQL::ORDER (ASC/DESC) and sorts by the vertex property.
  • If $definition is a string (legacy): Sorts by that string as the property on the vertex in ASC order.
  • If $definition is null (or AQL::SORT is not set in the array): Sorts by the $defaultProperty (e.g., 'created') on the edge in DESC order.
Parameters
$definition : array<string|int, mixed>|string|null

The sort configuration. Typically the $definition array from getEdgeVariable.

$vertexRef : string = AQL::VERTEX

The internal AQL vertex variable reference.

$edgeRef : string = AQL::EDGE

The internal AQL edge variable reference.

$defaultProperty : string = Schema::CREATED

The fallback property to sort by (default: 'created').

Tags
example

Assume the following constant values for the examples:

  • AQL::SORT = 'sort'
  • AQL::ORDER = 'order'
  • Order::DESC = 'DESC'
  • Order::ASC = 'ASC'
  • Schema::CREATED = 'created'
  • AQL::EDGE_PREFIX = 'e_'
  • AQL::VERTEX_PREFIX = 'v_'

Case 1: Default sort (null definition)

Sorts by 'created' on the edge (e_) in DESC order.

echo sortEdgeVariable( null , 'friends_rel');
// Output: "SORT e_friends_rel.created DESC"

Case 2: Legacy string sort (string definition)

Sorts by 'name' on the vertex (v_) in ASC order.

echo sortEdgeVariable( 'name' , 'friends_rel');
// Output: "SORT v_friends_rel.name ASC"

Case 3: Array definition (DESC)

Sorts by 'age' on the vertex (v_) in DESC order.

$definition =
[
    AQL::SORT  => 'age',
    AQL::ORDER => Order::DESC
];
echo sortEdgeVariable( $definition, 'friends_rel' );
// Output: "SORT v_friends_rel.age DESC"

Case 4: Array definition (ASC)

Sorts by 'lastName' on the vertex (v_) in ASC order.

$definition = [ AQL::SORT => 'lastName' ]; // AQL::ORDER defaults to ASC
echo sortEdgeVariable( $definition , 'friends_rel');
// Output: "SORT v_friends_rel.lastName ASC"

Case 5: Array definition missing 'sort' key ---

Falls back to default sort (Case 1).

$def5 = [ AQL::ORDER => Order::DESC ];
echo sortEdgeVariable($def5, 'friends_rel');
// Output: "SORT e_friends_rel.created DESC"
* ```
Return values
string

The generated AQL 'SORT' clause (e.g., "SORT v_myVar_collectionName.name ASC").

On this page

Search results