Skip to content

OPTIONAL MATCH clause

Marijn van Wezel edited this page Dec 13, 2022 · 5 revisions

The OPTIONAL MATCH clause accepts a list of patterns to (optionally) match on. Refer to the MATCH clause documentation for more information about the syntax of patterns.

Query::optionalMatch(CompletePattern|CompletePattern[] $patterns): Query

Parameters

  • $patterns : A single pattern to match, or a non-empty list of patterns to match.

Relevant methods

  • addPattern(CompletePattern ...$pattern): self : Add one or more patterns.

Examples

$movies = node("Movie");
$query = query()
    ->optionalMatch($movies)
    ->build();

$this->assertSame("OPTIONAL MATCH (:Movie)", $query);

External links