Oihana PHP Arango

pluck.php

Table of Contents

Functions

pluck()  : string
Project an array of objects onto a single sub-field.

Functions

pluck()

Project an array of objects onto a single sub-field.

pluck(string $array, string $field) : string

Builds the AQL inline projection array[* RETURN CURRENT.<field>], which maps an array of objects to an array holding only the requested sub-field of each element. Combined with an aggregate (AVERAGE, SUM, MAX, …) it lets a filter reduce over a property of embedded objects:

AVERAGE(doc.items[* RETURN CURRENT.price])   // average price across doc.items

The [* RETURN expr] form is AQL's array inline projection (the read-only sibling of the array filter [* FILTER cond]). Because $field is typically user-supplied (it comes from the alt chain), it is validated with assertAttributeName() before being interpolated, guarding against AQL injection.

Parameters
$array : string

The array expression to project (e.g. doc.items).

$field : string

The sub-field to keep from each element (e.g. price).

Tags
example
use function oihana\arango\db\functions\arrays\pluck;

$expr = pluck('doc.items', 'price');
// Produces: 'doc.items[* RETURN CURRENT.price]'
throws
ValidationException

When $field is not a safe attribute name.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL inline projection.

On this page

Search results