Oihana PHP Arango

aqlFieldBool.php

Table of Contents

Functions

aqlFieldBool()  : string
Generates an AQL key/value expression that converts a document field to boolean.

Functions

aqlFieldBool()

Generates an AQL key/value expression that converts a document field to boolean.

aqlFieldBool(string $key[, string $doc = AQL::DOC ][, string|null $keyName = null ][, array<string|int, mixed> $options = [] ]) : string

This helper builds a snippet suitable for a RETURN { ... } block in AQL. It references a field in the given document (or alias) and wraps it with the TO_BOOL() function, ensuring the value is interpreted as a boolean in AQL.

If $keyName is not provided, the $key parameter is used as both the resulting key in the object and the field name in the document.

Example usage:

// PHP call
aqlFieldBool('isActive');

// Generates
isActive: TO_BOOL(doc.isActive)

Abstaining (Field::NULLABLE):

TO_BOOL() answers even when nothing was asked: a document that says nothing about the attribute comes back with false, indistinguishable from one that stores false. An opt-in Field::NULLABLE guards the cast behind the presence of the attribute, and Field::ELSE picks what is said instead (default null):

aqlFieldBool( 'active' , 'doc' , null , [ Field::NULLABLE => true ] ) ;
// active:doc.active != null ? TO_BOOL(doc.active) : null

The test is != null, not IS_BOOL(): TO_BOOL() exists precisely to accept what is not a boolean — a document storing 1 or "yes" counts as true today — so a type test would make all of them abstain. The question asked is only « is the attribute there? ». Without the marker the emitted AQL is unchanged, byte for byte.

Parameters
$key : string

The key to use in the resulting AQL object (e.g. "isActive").

$doc : string = AQL::DOC

The document alias or variable name to reference (default: AQL::DOC).

$keyName : string|null = null

Optional field name in the document; if omitted, $key is used.

$options : array<string|int, mixed> = []

The field definition, read for the optional guard (Field::NULLABLE, Field::ELSE).

Tags
throws
UnsupportedOperationException

If the guard descriptor is malformed.

ValidationException

If an else attribute name is unsafe.

since
1.0.0
author

Marc Alcaraz

Return values
string

AQL key/value expression, e.g. "isActive: TO_BOOL(doc.isActive)".

On this page

Search results