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
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
$criteria
private
QueryCriteria
$criteria
$executed
private
bool
$executed
= false
$method
private
string
$method
= 'findBy'
$result
private
T|null
$result
= null
$service
private
ServiceInterface
$service
Methods
__construct()
public
__construct(ServiceInterface<string|int, T> $service, QueryCriteria $criteria[, string $method = 'findBy' ]) : mixed
Parameters
- $service : ServiceInterface<string|int, T>
- $criteria : QueryCriteria
- $method : string = 'findBy'
__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|nullexists()
Returns whether the entity exists.
public
exists() : bool
Return values
boolfilter()
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|nullgetOrFail()
Returns the entity or throws.
public
getOrFail() : T
Tags
Return values
Tinclude()
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
booluseCache()
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