CoolCMS API

SingleQuery
in package

Fluent query for one entity (`find()`, `findBy()`).

Lazy proxy: the entity is evaluated only by an explicit get(), execute() or getOrFail(). There is no magic __call(): to call an entity method, call get() or getOrFail() first. Otherwise the call fails fast with an undefined method error instead of silently hitting the proxy object.

Tags
template

Table of Contents

Properties

$criteria  : QueryCriteria
$executed  : bool
$method  : string
$result  : T|null
$service  : ServiceInterface

Methods

__construct()  : mixed
__debugInfo()  : array<string|int, mixed>
Returns the debug view of the query.
columns()  : T>
execute()  : T|null
Executes the query explicitly and returns the entity or null.
exists()  : bool
Returns whether the entity exists.
filter()  : T>
get()  : T|null
Alias of `execute()`.
getOrFail()  : T
Returns the entity or throws.
include()  : T>
isEmpty()  : bool
Returns whether the entity does not exist.
useCache()  : T>
Sets the query cache policy for this query.

Properties

Methods

__debugInfo()

Returns the debug view of the query.

public __debugInfo() : array<string|int, mixed>
Return values
array<string|int, mixed>

columns()

public columns(array<string|int, mixed> $columns) : T>
Parameters
$columns : array<string|int, mixed>
Return values
T>

execute()

Executes the query explicitly and returns the entity or null.

public execute() : T|null
Return values
T|null

exists()

Returns whether the entity exists.

public exists() : bool
Return values
bool

filter()

public filter(array<string|int, mixed> $filters) : T>
Parameters
$filters : array<string|int, mixed>
Return values
T>

get()

Alias of `execute()`.

public get() : T|null
Return values
T|null

getOrFail()

Returns the entity or throws.

public getOrFail() : T
Tags
throws
RuntimeException

when the entity is not found

Return values
T

include()

public include(string|array<string|int, mixed> $include) : T>
Parameters
$include : string|array<string|int, mixed>
Return values
T>

isEmpty()

Returns whether the entity does not exist.

public isEmpty() : bool
Return values
bool

useCache()

Sets the query cache policy for this query.

public useCache([bool $useCache = true ]) : T>

->useCache(false) reads from the database and ignores the cache; use it for exceptions where a stale value hurts (counters, read before write). Without the call the layer default applies: the front end caches, the admin does not (ApiRepository).

Usage:

$manager->find($id)->include(['translations'])->useCache(false)->get();
Parameters
$useCache : bool = true
Return values
T>
On this page

Search results