ModelQuery
extends PdbModelQuery
in package
Base model query
Tags
Table of Contents
Properties
- $_deleted : bool|null
- $_inflect : bool|string
- $date_added : array<string|int, DateTimeInterface|null>
- $date_modified : array<string|int, DateTimeInterface|null>
- $id : null|int
- $uid : null|string
- $_as : string|null
- $_cache_key : string|null
- Override the cache key.
- $_cache_ttl : int|bool
- - true: use `pdb.config.ttl` - false: no cache (default) - int: cache for this many seconds
- $_from : PdbQueryInterface, 1: string|null}|null
- single [field, alias]
- $_group : array<string|int, string>
- $_having : array<string|int, PdbConditionInterface, 2: string}>
- list [type, conditions, combine]
- $_joins : array<string|int, PdbConditionInterface, 3: string}>
- list [ type, [table, alias], conditions, combine ]
- $_keyed : string|null
- $_limit : int
- $_model : T>
- $_offset : int
- $_order : array<string|int, mixed>
- $_select : array<string|int, mixed>
- $_throw : bool
- $_union : array<string|int, PdbQueryInterface>
- $_where : array<string|int, PdbConditionInterface, 2: string}>
- list [type, conditions, combine]
- $_with : array<string|int, PdbQueryInterface, 1: string}>
- list [query, alias]
- $pdb : Pdb
Methods
- __construct() : mixed
- addedAfter() : $this
- addedBefore() : $this
- addedBetween() : $this
- alias() : static
- Set the alias for the FROM table.
- all() : array<string|int, T>
- andSelect() : static
- Select more things.
- andWhere() : static
- as() : static
- batch() : Generator<string|int, array<string|int, mixed>>
- build() : array<string|int, mixed>
- cache() : static
- clone() : static
- Get a copy of this query.
- column() : array<string|int, mixed>
- count() : int
- deleted() : $this
- each() : Generator
- execute() : mixed
- exists() : bool
- find() : static
- from() : static
- Set the FROM table and alias (optional).
- getAlias() : string
- Get the query table alias.
- getIdentifiers() : array<string|int, string|PdbQueryInterface>
- getReturnConfig() : PdbReturnInterface
- group() : static
- groupBy() : static
- having() : static
- id() : $this
- indexBy() : static
- Specify a key for array results.
- inflect() : $this
- Enable table name inflection.
- innerJoin() : static
- iterator() : Generator
- join() : static
- jsonSerialize() : array<string|int, mixed>
- keyed() : array<string|int, mixed>
- This ends a query.
- leftJoin() : static
- limit() : static
- map() : array<string|int, mixed>
- modifiedAfter() : $this
- modifiedBefore() : $this
- modifiedBetween() : $this
- offset() : static
- one() : T))
- order() : static
- orderBy() : static
- orWhere() : static
- pdo() : PDOStatement
- select() : static
- Select a list of fields.
- throw() : static
- Emit RowMissingExceptions if the record is not found.
- toArray() : array<string|int, mixed>
- Convert this object to an array.
- uid() : $this
- union() : static
- Add a sub-query to the UNION clause.
- update() : void
- Update the object with a new configuration.
- validate() : void
- value() : string|null
- where() : static
- with() : static
- Add a sub-query to the WITH clause.
- _afterBuild() : void
- _beforeBuild() : void
- _build() : array<string|int, mixed>
- _join() : static
Properties
$_deleted
public
bool|null
$_deleted
= null
$_inflect
public
bool|string
$_inflect
= false
$date_added
public
array<string|int, DateTimeInterface|null>
$date_added
= [null, null]
[ after, before ]
$date_modified
public
array<string|int, DateTimeInterface|null>
$date_modified
= [null, null]
[ after, before ]
$id
public
null|int
$id
= null
$uid
public
null|string
$uid
= null
$_as
protected
string|null
$_as
= null
$_cache_key
Override the cache key.
protected
string|null
$_cache_key
= null
$_cache_ttl
- true: use `pdb.config.ttl` - false: no cache (default) - int: cache for this many seconds
protected
int|bool
$_cache_ttl
= false
$_from
single [field, alias]
protected
PdbQueryInterface, 1: string|null}|null
$_from
= null
$_group
protected
array<string|int, string>
$_group
= []
$_having
list [type, conditions, combine]
protected
array<string|int, PdbConditionInterface, 2: string}>
$_having
= []
$_joins
list [ type, [table, alias], conditions, combine ]
protected
array<string|int, PdbConditionInterface, 3: string}>
$_joins
= []
$_keyed
protected
string|null
$_keyed
= null
$_limit
protected
int
$_limit
= 0
$_model
protected
T>
$_model
$_offset
protected
int
$_offset
= 0
$_order
protected
array<string|int, mixed>
$_order
= []
list [field, order]
$_select
protected
array<string|int, mixed>
$_select
= []
list [field, alias]
$_throw
protected
bool
$_throw
= true
$_union
protected
array<string|int, PdbQueryInterface>
$_union
= []
$_where
list [type, conditions, combine]
protected
array<string|int, PdbConditionInterface, 2: string}>
$_where
= []
$_with
list [query, alias]
protected
array<string|int, PdbQueryInterface, 1: string}>
$_with
= []
$pdb
protected
Pdb
$pdb
Methods
__construct()
public
__construct(T> $model[, array<string, mixed> $config = [] ]) : mixed
Parameters
- $model : T>
- $config : array<string, mixed> = []
Tags
addedAfter()
public
addedAfter(null|int|float|string|DateTimeInterface $date) : $this
Parameters
- $date : null|int|float|string|DateTimeInterface
Return values
$thisaddedBefore()
public
addedBefore(null|int|float|string|DateTimeInterface $date) : $this
Parameters
- $date : null|int|float|string|DateTimeInterface
Return values
$thisaddedBetween()
public
addedBetween(null|int|float|string|DateTimeInterface $after, null|int|float|string|DateTimeInterface $before) : $this
Parameters
- $after : null|int|float|string|DateTimeInterface
- $before : null|int|float|string|DateTimeInterface
Return values
$thisalias()
Set the alias for the FROM table.
public
alias(string $alias) : static
This can only modify an existing FROM statement.
Parameters
- $alias : string
Tags
Return values
staticall()
public
all() : array<string|int, T>
Return values
array<string|int, T>andSelect()
Select more things.
public
andSelect(string|array<string|int, string> ...$fields) : static
This does not replace previous select(), only adds.
Parameters
- $fields : string|array<string|int, string>
-
alias => column
Tags
Return values
staticandWhere()
public
andWhere(array<string|int, mixed>|PdbConditionInterface $conditions[, string $combine = 'AND' ]) : static
Parameters
- $conditions : array<string|int, mixed>|PdbConditionInterface
- $combine : string = 'AND'
-
AND | OR
Return values
staticas()
public
as(string|null $class) : static
Parameters
- $class : string|null
Tags
Return values
staticbatch()
public
batch(int $size) : Generator<string|int, array<string|int, mixed>>
Parameters
- $size : int
Tags
Return values
Generator<string|int, array<string|int, mixed>>build()
public
build([bool $validate = true ]) : array<string|int, mixed>
Parameters
- $validate : bool = true
Tags
Return values
array<string|int, mixed> —[ sql, params ]
cache()
public
cache([string|null $key = null ][, int|bool $ttl = true ]) : static
Parameters
- $key : string|null = null
- $ttl : int|bool = true
-
seconds
Return values
staticclone()
Get a copy of this query.
public
clone() : static
Return values
staticcolumn()
public
column([string|null $field = null ]) : array<string|int, mixed>
Parameters
- $field : string|null = null
Tags
Return values
array<string|int, mixed>count()
public
count() : int
Tags
Return values
intdeleted()
public
deleted(bool|null $deleted) : $this
Parameters
- $deleted : bool|null
Return values
$thiseach()
public
each(int $size) : Generator
Parameters
- $size : int
Tags
Return values
Generatorexecute()
public
execute(string $return_type) : mixed
Parameters
- $return_type : string
Tags
exists()
public
exists() : bool
Tags
Return values
boolfind()
public
find(string|array<string|int, string>|PdbQueryInterface $table[, array<string|int, mixed>|PdbConditionInterface $conditions = [] ]) : static
Parameters
- $table : string|array<string|int, string>|PdbQueryInterface
- $conditions : array<string|int, mixed>|PdbConditionInterface = []
Return values
staticfrom()
Set the FROM table and alias (optional).
public
from(string|array<string|int, string>|PdbQueryInterface $table[, string $alias = null ]) : static
Parameters
- $table : string|array<string|int, string>|PdbQueryInterface
- $alias : string = null
Tags
Return values
staticgetAlias()
Get the query table alias.
public
getAlias() : string
Tags
Return values
stringgetIdentifiers()
public
getIdentifiers() : array<string|int, string|PdbQueryInterface>
Return values
array<string|int, string|PdbQueryInterface> —[ alias => table ]
getReturnConfig()
public
getReturnConfig(string $return_type) : PdbReturnInterface
Parameters
- $return_type : string
Tags
Return values
PdbReturnInterfacegroup()
public
group(string|array<string|int, string> ...$fields) : static
use groupBy
Parameters
- $fields : string|array<string|int, string>
Return values
staticgroupBy()
public
groupBy(string|array<string|int, string> ...$fields) : static
Parameters
- $fields : string|array<string|int, string>
Return values
statichaving()
public
having(array<string|int, mixed>|PdbConditionInterface $conditions[, string $combine = 'AND' ]) : static
Parameters
- $conditions : array<string|int, mixed>|PdbConditionInterface
- $combine : string = 'AND'
Return values
staticid()
public
id(string|int|null $id) : $this
Parameters
- $id : string|int|null
Return values
$thisindexBy()
Specify a key for array results.
public
indexBy(string|null $field) : static
This applies to:
- all()
- column()
- iterator()
Parameters
- $field : string|null
Return values
staticinflect()
Enable table name inflection.
public
inflect([bool $inflect = true ]) : $this
This will automatically alias table names for FROM statements. But only if the table name is not already aliased.
Example:
sprout_sites => site
Note, this will also strip prefixes from tables, inflected or not. Meaning table names that are already singular remain singular but lose their prefix.
Example:
sprout_file_join => file_join
Parameters
- $inflect : bool = true
Tags
Return values
$thisinnerJoin()
public
innerJoin(string|array<string|int, string> $table, string|array<string|int, mixed>|PdbConditionInterface $conditions[, string $combine = 'AND' ]) : static
Parameters
- $table : string|array<string|int, string>
- $conditions : string|array<string|int, mixed>|PdbConditionInterface
- $combine : string = 'AND'
Return values
staticiterator()
public
iterator() : Generator
Tags
Return values
Generatorjoin()
public
join(string|array<string|int, string> $table, string|array<string|int, mixed>|PdbConditionInterface $conditions[, string $combine = 'AND' ]) : static
Parameters
- $table : string|array<string|int, string>
- $conditions : string|array<string|int, mixed>|PdbConditionInterface
- $combine : string = 'AND'
Return values
staticjsonSerialize()
public
jsonSerialize() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>keyed()
This ends a query.
public
keyed(string $key) : array<string|int, mixed>
Parameters
- $key : string
Tags
Return values
array<string|int, mixed> —[ $key => item ]
leftJoin()
public
leftJoin(string|array<string|int, string> $table, string|array<string|int, mixed>|PdbConditionInterface $conditions[, string $combine = 'AND' ]) : static
Parameters
- $table : string|array<string|int, string>
- $conditions : string|array<string|int, mixed>|PdbConditionInterface
- $combine : string = 'AND'
Return values
staticlimit()
public
limit(int $limit) : static
Parameters
- $limit : int
Return values
staticmap()
public
map([array<string|int, mixed>|string|null $key = null ][, string|null $value = null ]) : array<string|int, mixed>
Parameters
- $key : array<string|int, mixed>|string|null = null
- $value : string|null = null
Tags
Return values
array<string|int, mixed>modifiedAfter()
public
modifiedAfter(null|int|float|string|DateTimeInterface $date) : $this
Parameters
- $date : null|int|float|string|DateTimeInterface
Return values
$thismodifiedBefore()
public
modifiedBefore(null|int|float|string|DateTimeInterface $date) : $this
Parameters
- $date : null|int|float|string|DateTimeInterface
Return values
$thismodifiedBetween()
public
modifiedBetween(null|int|float|string|DateTimeInterface $after, null|int|float|string|DateTimeInterface $before) : $this
Parameters
- $after : null|int|float|string|DateTimeInterface
- $before : null|int|float|string|DateTimeInterface
Return values
$thisoffset()
public
offset(int $offset) : static
Parameters
- $offset : int
Return values
staticone()
public
one([bool|null $throw = = 'null' ]) : T))
Parameters
- $throw : bool|null = = 'null'
Return values
T))order()
public
order(string|array<string|int, string> ...$fields) : static
use orderBy
Parameters
- $fields : string|array<string|int, string>
Return values
staticorderBy()
public
orderBy(string|array<string|int, string> ...$fields) : static
Parameters
- $fields : string|array<string|int, string>
Return values
staticorWhere()
public
orWhere(array<string|int, mixed>|PdbConditionInterface $conditions[, string $combine = 'OR' ]) : static
Parameters
- $conditions : array<string|int, mixed>|PdbConditionInterface
- $combine : string = 'OR'
-
AND | OR
Return values
staticpdo()
public
pdo() : PDOStatement
Tags
Return values
PDOStatementselect()
Select a list of fields.
public
select(string|array<string|int, string> ...$fields) : static
Note, this will replace any previous select().
Parameters
- $fields : string|array<string|int, string>
-
alias => column
Tags
Return values
staticthrow()
Emit RowMissingExceptions if the record is not found.
public
throw([bool $throw = true ]) : static
This applies to:
- one()
- value()
Parameters
- $throw : bool = true
Return values
statictoArray()
Convert this object to an array.
public
toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>uid()
public
uid(string|null $uid) : $this
Parameters
- $uid : string|null
Return values
$thisunion()
Add a sub-query to the UNION clause.
public
union(PdbQueryInterface $query) : static
Parameters
- $query : PdbQueryInterface
Return values
staticupdate()
Update the object with a new configuration.
public
update(iterable<string|int, mixed> $config) : void
Parameters
- $config : iterable<string|int, mixed>
validate()
public
validate() : void
Tags
value()
public
value([string|null $field = null ][, bool|null $throw = null ]) : string|null
Parameters
- $field : string|null = null
- $throw : bool|null = null
Tags
Return values
string|nullwhere()
public
where(array<string|int, mixed>|PdbConditionInterface $conditions[, string $combine = 'AND' ]) : static
Parameters
- $conditions : array<string|int, mixed>|PdbConditionInterface
- $combine : string = 'AND'
Return values
staticwith()
Add a sub-query to the WITH clause.
public
with(PdbQueryInterface $query, string $alias) : static
Parameters
- $query : PdbQueryInterface
- $alias : string
Return values
static_afterBuild()
protected
_afterBuild(string &$sql, array<string|int, mixed> &$params) : void
Parameters
- $sql : string
- $params : array<string|int, mixed>
_beforeBuild()
protected
_beforeBuild(PdbQuery &$query) : void
Parameters
- $query : PdbQuery
Tags
_build()
protected
_build([bool $validate = true ]) : array<string|int, mixed>
Parameters
- $validate : bool = true
Tags
Return values
array<string|int, mixed> —[ sql, params ]
_join()
protected
_join(string $type, string|array<string|int, string> $table, string|array<string|int, mixed>|PdbConditionInterface $conditions[, string $combine = 'AND' ]) : static
Parameters
- $type : string
- $table : string|array<string|int, string>
- $conditions : string|array<string|int, mixed>|PdbConditionInterface
- $combine : string = 'AND'