Oihana PHP Arango

sortRelationVariable.php

Table of Contents

Functions

sortRelationVariable()  : string
Generates the internal AQL 'SORT' clause for a relation sub-query (edge or join).

Functions

sortRelationVariable()

Generates the internal AQL 'SORT' clause for a relation sub-query (edge or join).

sortRelationVariable(array<string|int, mixed>|string|null $definition, string $sortRef, string $defaultRef[, string $defaultProperty = Schema::CREATED ]) : string

This helper interprets a flexible sort definition and constructs the appropriate AQL 'SORT' expression, shared by sortEdgeVariable() and sortJoinVariable(). The only thing those two wrappers customize is which variable reference carries the sort property and which one carries the default fallback property:

  • An explicit sort property (string definition, or AQL::SORT in an array) is sorted on $sortRef (the vertex for an edge, the join document for a join).
  • The fallback (no AQL::SORT provided) sorts by $defaultProperty on $defaultRef in DESC order (the edge for an edge relation, the same join document for a join).
Parameters
$definition : array<string|int, mixed>|string|null

The sort configuration (a $definition array, a legacy string, or null).

$sortRef : string

The AQL variable reference carrying an explicit sort property.

$defaultRef : string

The AQL variable reference carrying the fallback default property.

$defaultProperty : string = Schema::CREATED

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

Tags
example
// Explicit sort on the sortRef (ASC by default)
echo sortRelationVariable( 'name' , 'v' , 'e' );          // SORT v.name ASC

// Explicit sort with order
echo sortRelationVariable( [ AQL::SORT => 'age' , AQL::ORDER => Order::DESC ] , 'v' , 'e' ); // SORT v.age DESC

// Fallback on the defaultRef in DESC
echo sortRelationVariable( null , 'v' , 'e' );            // SORT e.created DESC
Return values
string

The generated AQL 'SORT' clause.

On this page

Search results