ElementQueryInterface

Type
Interface
Namespace
craft\elements\db
Extends
ArrayAccess, Countable, IteratorAggregate, yii\base\Arrayable, yii\db\QueryInterface
Implemented by
craft\elements\db\AssetQuery, craft\elements\db\CategoryQuery, craft\elements\db\ElementQuery, craft\elements\db\EntryQuery, craft\elements\db\GlobalSetQuery, craft\elements\db\MatrixBlockQuery, craft\elements\db\TagQuery, craft\elements\db\UserQuery
Since
3.0

ElementQueryInterface defines the common interface to be implemented by element query classes.

The default implementation of this interface is provided by craft\elements\db\ElementQuery.

View source

Public Methods

MethodDescription
addOrderBy()Adds additional ORDER BY columns to the query.
all()Executes the query and returns all results as an array.
ancestorDist()Sets the \craft\elements\db\$ancestorDist property.
ancestorOf()Sets the \craft\elements\db\$ancestorOf property.
andFilterWhere()Adds an additional WHERE condition to the existing one ignoring empty parameters.
andWhere()Adds an additional WHERE condition to the existing one.
andWith()Appends a value to the with() property.
archived()Sets the \craft\elements\db\$archived property.
asArray()Sets the \craft\elements\db\$asArray property.
count()Returns the number of records.
dateCreated()Sets the \craft\elements\db\$dateCreated property.
dateUpdated()Sets the \craft\elements\db\$dateUpdated property.
descendantDist()Sets the \craft\elements\db\$descendantDist property.
descendantOf()Sets the \craft\elements\db\$descendantOf property.
emulateExecution()Sets whether to emulate query execution, preventing any interaction with data storage.
enabledForSite()Sets the \craft\elements\db\$enabledForSite property.
exists()Returns a value indicating whether the query result contains any row of data.
extraFields()Returns the list of additional fields that can be returned by toArray() in addition to those listed in fields().
fields()Returns the list of fields that should be returned by default by toArray() when no specific fields are specified.
filterWhere()Sets the WHERE part of the query ignoring empty parameters.
fixedOrder()Sets the \craft\elements\db\$fixedOrder property.
hasDescendants()Sets the \craft\elements\db\$hasDescendants property.
id()Sets the \craft\elements\db\$id property.
ids()Executes the query and returns the IDs of the resulting elements.
indexBy()Sets the indexBy() property.
level()Sets the \craft\elements\db\$level property.
limit()Sets the LIMIT part of the query.
nextSiblingOf()Sets the \craft\elements\db\$nextSiblingOf property.
nth()Executes the query and returns a single row of result at a given offset.
offset()Sets the OFFSET part of the query.
one()Executes the query and returns a single row of result.
orFilterWhere()Adds an additional WHERE condition to the existing one ignoring empty parameters.
orWhere()Adds an additional WHERE condition to the existing one.
orderBy()Sets the ORDER BY part of the query.
positionedAfter()Sets the \craft\elements\db\$positionedAfter property.
positionedBefore()Sets the \craft\elements\db\$positionedBefore property.
prevSiblingOf()Sets the \craft\elements\db\$prevSiblingOf property.
ref()Sets the \craft\elements\db\$ref property.
relatedTo()Sets the \craft\elements\db\$relatedTo property.
search()Sets the \craft\elements\db\$search property.
siblingOf()Sets the \craft\elements\db\$siblingOf property.
site()Sets the \craft\elements\db\$siteId property based on a given site’s handle.
siteId()Sets the \craft\elements\db\$siteId property.
slug()Sets the \craft\elements\db\$slug property.
status()Sets the \craft\elements\db\$status property.
structureId()Sets the \craft\elements\db\$structureId property.
title()Sets the \craft\elements\db\$title property.
toArray()Converts the object into an array.
uid()Sets the \craft\elements\db\$uid property.
uri()Sets the \craft\elements\db\$uri property.
where()Sets the WHERE part of the query.
with()Sets the \craft\elements\db\$with property.
withStructure()Sets the \craft\elements\db\$withStructure property.

all()

Executes the query and returns all results as an array.

View source

Arguments

  • $db (yii\db\Connection, null) – The database connection used to generate the SQL statement. If this parameter is not given, the db application component will be used.

Returns

craft\base\ElementInterface[] – The resulting elements.

Signature

public abstract craft\base\ElementInterface[] all ( $db = null )

ancestorDist()

Sets the \craft\elements\db\$ancestorDist property.

View source

Arguments

Returns

static – Self reference

Signature

public abstract static ancestorDist ( \craft\elements\db\int $value = null )

ancestorOf()

Sets the \craft\elements\db\$ancestorOf property.

View source

Arguments

Returns

static – Self reference

Signature

public abstract static ancestorOf ( $value )

andWith()

Appends a value to the with() property.

View source

Arguments

Returns

self – The query object itself

Signature

public abstract self andWith ( $value )

archived()

Sets the \craft\elements\db\$archived property.

View source

Arguments

  • $value (boolean) – The property value (defaults to true)

Returns

static – Self reference

Signature

public abstract static archived ( \craft\elements\db\bool $value = true )

asArray()

Sets the \craft\elements\db\$asArray property.

View source

Arguments

  • $value (boolean) – The property value (defaults to true)

Returns

static – Self reference

Signature

public abstract static asArray ( \craft\elements\db\bool $value = true )

dateCreated()

Sets the \craft\elements\db\$dateCreated property.

View source

Arguments

  • $value (mixed) – The property value

Returns

static – Self reference

Signature

public abstract static dateCreated ( $value )

dateUpdated()

Sets the \craft\elements\db\$dateUpdated property.

View source

Arguments

  • $value (mixed) – The property value

Returns

static – Self reference

Signature

public abstract static dateUpdated ( $value )

descendantDist()

Sets the \craft\elements\db\$descendantDist property.

View source

Arguments

Returns

static – Self reference

Signature

public abstract static descendantDist ( \craft\elements\db\int $value = null )

descendantOf()

Sets the \craft\elements\db\$descendantOf property.

View source

Arguments

Returns

static – Self reference

Signature

public abstract static descendantOf ( $value )

enabledForSite()

Sets the \craft\elements\db\$enabledForSite property.

View source

Arguments

  • $value (boolean) – The property value (defaults to true)

Returns

static – Self reference

Signature

public abstract static enabledForSite ( \craft\elements\db\bool $value = true )

fixedOrder()

Sets the \craft\elements\db\$fixedOrder property.

View source

Arguments

  • $value (boolean) – The property value (defaults to true)

Returns

static – Self reference

Signature

public abstract static fixedOrder ( \craft\elements\db\bool $value = true )

hasDescendants()

Sets the \craft\elements\db\$hasDescendants property.

View source

Arguments

  • $value (boolean) – The property value

Returns

static – Self reference

Signature

public abstract static hasDescendants ( \craft\elements\db\bool $value = true )

id()

Sets the \craft\elements\db\$id property.

View source

Arguments

Returns

static – Self reference

Signature

public abstract static id ( $value )

ids()

Executes the query and returns the IDs of the resulting elements.

View source

Arguments

  • $db (yii\db\Connection, null) – The database connection used to generate the SQL statement. If this parameter is not given, the db application component will be used.

Returns

integer[] – The resulting element IDs. An empty array is returned if no elements are found.

Signature

public abstract integer[] ids ( $db = null )

level()

Sets the \craft\elements\db\$level property.

View source

Arguments

  • $value (mixed) – The property value

Returns

static – Self reference

Signature

public abstract static level ( $value = null )

nextSiblingOf()

Sets the \craft\elements\db\$nextSiblingOf property.

View source

Arguments

Returns

static – Self reference

Signature

public abstract static nextSiblingOf ( $value )

nth()

Executes the query and returns a single row of result at a given offset.

View source

Arguments

  • $n (integer) – The offset of the row to return. If offset() is set, $offset will be added to it.
  • $db (yii\db\Connection, null) – The database connection used to generate the SQL statement. If this parameter is not given, the db application component will be used.

Returns

craft\base\ElementInterface, array, null – The element or row of the query result. Null is returned if the query results in nothing.

Signature

public abstract craft\base\ElementInterface, array, null nth ( \craft\elements\db\int $n, yii\db\Connection $db = null )

one()

Executes the query and returns a single row of result.

View source

Arguments

  • $db (yii\db\Connection) – The database connection used to execute the query. If this parameter is not given, the db application component will be used.

Returns

craft\base\ElementInterface, array, null – The resulting element. Null is returned if the query results in nothing.

Signature

public abstract craft\base\ElementInterface, array, null one ( $db = null )

positionedAfter()

Sets the \craft\elements\db\$positionedAfter property.

View source

Arguments

Returns

static – Self reference

Signature

public abstract static positionedAfter ( $value )

positionedBefore()

Sets the \craft\elements\db\$positionedBefore property.

View source

Arguments

Returns

static – Self reference

Signature

public abstract static positionedBefore ( $value )

prevSiblingOf()

Sets the \craft\elements\db\$prevSiblingOf property.

View source

Arguments

Returns

static – Self reference

Signature

public abstract static prevSiblingOf ( $value )

ref()

Sets the \craft\elements\db\$ref property.

View source

Arguments

Returns

static – Self reference

Signature

public abstract static ref ( $value )

relatedTo()

Sets the \craft\elements\db\$relatedTo property.

View source

Arguments

Returns

static – Self reference

Signature

public abstract static relatedTo ( $value )

Sets the \craft\elements\db\$search property.

View source

Arguments

Returns

static – Self reference

Signature

public abstract static search ( $value )

siblingOf()

Sets the \craft\elements\db\$siblingOf property.

View source

Arguments

Returns

static – Self reference

Signature

public abstract static siblingOf ( $value )

site()

Sets the \craft\elements\db\$siteId property based on a given site’s handle.

View source

Arguments

Returns

static – Self reference

Signature

public abstract static site ( $value )

siteId()

Sets the \craft\elements\db\$siteId property.

View source

Arguments

Returns

static – Self reference

Signature

public abstract static siteId ( \craft\elements\db\int $value = null )

slug()

Sets the \craft\elements\db\$slug property.

View source

Arguments

Returns

static – Self reference

Signature

public abstract static slug ( $value )

status()

Sets the \craft\elements\db\$status property.

View source

Arguments

Returns

static – Self reference

Signature

public abstract static status ( $value )

structureId()

Sets the \craft\elements\db\$structureId property.

View source

Arguments

Returns

static – Self reference

Signature

public abstract static structureId ( \craft\elements\db\int $value = null )

title()

Sets the \craft\elements\db\$title property.

View source

Arguments

Returns

static – Self reference

Signature

public abstract static title ( $value )

uid()

Sets the \craft\elements\db\$uid property.

View source

Arguments

Returns

static – Self reference

Signature

public abstract static uid ( $value )

uri()

Sets the \craft\elements\db\$uri property.

View source

Arguments

Returns

static – Self reference

Signature

public abstract static uri ( $value )

with()

Sets the \craft\elements\db\$with property.

View source

Arguments

Returns

self – The query object itself

Signature

public abstract self with ( $value )

withStructure()

Sets the \craft\elements\db\$withStructure property.

View source

Arguments

  • $value (boolean) – The property value (defaults to true)

Returns

static – Self reference

Signature

public abstract static withStructure ( \craft\elements\db\bool $value = true )