Oihana PHP Arango

resolveWhenElse.php

Table of Contents

Functions

resolveWhenElse()  : string
Resolve the `Field::ELSE` branch of a conditional field into an AQL expression.

Functions

resolveWhenElse()

Resolve the `Field::ELSE` branch of a conditional field into an AQL expression.

resolveWhenElse([mixed $else = null ][, string $doc = AQL::DOC ]) : string

Two forms:

  • Attribute reference[ Field::PROPERTY => '<attr>' ]doc.<attr> (validated by assertAttributeName()), so the fallback can mirror another document attribute.
  • Literal — anything else (a scalar, an array of scalars, or null — the default) is inlined via aqlValue().

⚠️ A string literal is quoted by aqlValue() unless it already looks like AQL — which is deliberate (it is what lets a condition compare two attributes, [ 'price', 'gt', 'doc.minPrice' ]). A few real-world literals fall into that net: 'N/A' and 'en/US' have the shape of a document handle (collection/key) and are emitted raw, which ArangoDB then reads as code and refuses (error 1203). Declare an ambiguous literal — one containing a / or a . — with betweenQuotes(), the explicit « this really is a string » form, which passes through untouched:

Field::ELSE => betweenQuotes( 'N/A' ) ,   // →  : 'N/A'
Parameters
$else : mixed = null

The Field::ELSE descriptor (default null).

$doc : string = AQL::DOC

The document reference (default: AQL::DOC).

Tags
throws
UnsupportedOperationException
ValidationException

If the referenced attribute name is unsafe.

since
1.3.0
author

Marc Alcaraz

Return values
string

The AQL expression for the else branch (null, 0, 'unknown', doc.basePrice, …).

On this page

Search results