Craft 3 Class Reference

Class craft\elements\db\AssetQuery

Inheritance
craft\elements\db\AssetQuery » craft\elements\db\ElementQuery » craft\db\Query » yii\db\Query » yii\base\Component » yii\base\BaseObject
Implements
craft\elements\db\ElementQueryInterface, yii\base\Configurable, yii\db\ExpressionInterface, yii\db\QueryInterface
Uses Traits
yii\base\ArrayableTrait, yii\db\QueryTrait
Available since version
3.0
Source Code
https://github.com/craftcms/cms/blob/master/src/elements/db/AssetQuery.php

AssetQuery represents a SELECT SQL statement for assets in a way that is independent of DBMS.

Public Properties
Property Type Description Defined By
$ancestorDist integer, null The maximum number of levels that results may be separated from ancestorOf(). craft\elements\db\ElementQuery
$ancestorOf integer, craft\base\ElementInterface, null The element (or its ID) that results must be an ancestor of. craft\elements\db\ElementQuery
$archived boolean Whether to return only archived elements. craft\elements\db\ElementQuery
$asArray boolean Whether to return each element as an array. craft\elements\db\ElementQuery
$contentTable string, null The content table that will be joined by this query. craft\elements\db\ElementQuery
$customFields craft\base\FieldInterface[], null The fields that may be involved in this query. craft\elements\db\ElementQuery
$dateCreated mixed When the resulting elements must have been created. craft\elements\db\ElementQuery
$dateModified mixed The Date Modified that the resulting assets must have. craft\elements\db\AssetQuery
$dateUpdated mixed When the resulting elements must have been last updated. craft\elements\db\ElementQuery
$descendantDist integer, null The maximum number of levels that results may be separated from descendantOf(). craft\elements\db\ElementQuery
$descendantOf integer, craft\base\ElementInterface, null The element (or its ID) that results must be a descendant of. craft\elements\db\ElementQuery
$distinct boolean Whether to select distinct rows of data only. yii\db\Query
$elementType string, null The name of the craft\base\ElementInterface class. craft\elements\db\ElementQuery
$emulateExecution boolean Whether to emulate the actual query execution, returning empty or false results. yii\db\QueryTrait
$enabledForSite boolean Whether the elements must be enabled for the chosen site. craft\elements\db\ElementQuery
$filename string, string[], null The filename(s) that the resulting assets must have. craft\elements\db\AssetQuery
$fixedOrder boolean Whether results should be returned in the order specified by id(). craft\elements\db\ElementQuery
$folderId integer, integer[], null The asset folder ID(s) that the resulting assets must be in. craft\elements\db\AssetQuery
$from array The table(s) to be selected from. yii\db\Query
$groupBy array How to group the query results. yii\db\Query
$having string, array, yii\db\ExpressionInterface The condition to be applied in the GROUP BY clause. yii\db\Query
$height integer, null The height (in pixels) that the resulting assets must have. craft\elements\db\AssetQuery
$id integer, integer[], false, null The element ID(s). craft\elements\db\ElementQuery
$inReverse boolean Whether the results should be queried in reverse. craft\elements\db\ElementQuery
$includeSubfolders boolean Whether the query should search the subfolders of folderId(). craft\elements\db\AssetQuery
$indexBy string, callable The name of the column by which the query results should be indexed by. yii\db\QueryTrait
$join array How to join with other tables. yii\db\Query
$kind string, string[], null The file kind(s) that the resulting assets must be. craft\elements\db\AssetQuery
$level mixed The element’s level within the structure craft\elements\db\ElementQuery
$limit integer, yii\db\ExpressionInterface Maximum number of records to be returned. yii\db\QueryTrait
$nextSiblingOf integer, craft\base\ElementInterface, null The element (or its ID) that the result must be the next sibling of. craft\elements\db\ElementQuery
$offset integer, yii\db\ExpressionInterface Zero-based offset from where the records are to be returned. yii\db\QueryTrait
$orderBy array How to sort the query results. yii\db\QueryTrait
$params array List of query parameter values indexed by parameter placeholders. yii\db\Query
$positionedAfter integer, craft\base\ElementInterface, null The element (or its ID) that the results must be positioned after. craft\elements\db\ElementQuery
$positionedBefore integer, craft\base\ElementInterface, null The element (or its ID) that the results must be positioned before. craft\elements\db\ElementQuery
$prevSiblingOf integer, craft\base\ElementInterface, null The element (or its ID) that the result must be the previous sibling of. craft\elements\db\ElementQuery
$query craft\db\Query, null The query object created by prepare() craft\elements\db\ElementQuery
$queryCacheDependency yii\caching\Dependency The dependency to be associated with the cached query result for this query yii\db\Query
$queryCacheDuration integer, true The default number of seconds that query results can remain valid in cache. yii\db\Query
$ref string, string[], null The reference code(s) used to identify the element(s). craft\elements\db\ElementQuery
$relatedTo integer, array, craft\base\ElementInterface, null The element relation criteria. craft\elements\db\ElementQuery
$search string, array, craft\search\SearchQuery, null The search term to filter the resulting elements by. craft\elements\db\ElementQuery
$select array The columns being selected. yii\db\Query
$selectOption string Additional option that should be appended to the 'SELECT' keyword. yii\db\Query
$siblingOf integer, craft\base\ElementInterface, null The element (or its ID) that the results must be a sibling of. craft\elements\db\ElementQuery
$siteId integer, null The site ID that the elements should be returned in. craft\elements\db\ElementQuery
$size integer, null The size (in bytes) that the resulting assets must have. craft\elements\db\AssetQuery
$slug string, string[], null The slug that resulting elements must have. craft\elements\db\ElementQuery
$status string, string[], null The status(es) that the resulting elements must have. craft\elements\db\ElementQuery
$structureId integer, false, null The structure ID that should be used to join in the structureelements table. craft\elements\db\ElementQuery
$subQuery craft\db\Query, null The subselect’s query object created by prepare() craft\elements\db\ElementQuery
$title string, string[], null The title that resulting elements must have. craft\elements\db\ElementQuery
$uid string, string[], null The element UID(s). craft\elements\db\ElementQuery
$union array This is used to construct the UNION clause(s) in a SQL statement. yii\db\Query
$uri string, string[], null The URI that the resulting element must have. craft\elements\db\ElementQuery
$volumeId integer, integer[], null The volume ID(s) that the resulting assets must be in. craft\elements\db\AssetQuery
$where string, array Query condition. yii\db\QueryTrait
$width integer, null The width (in pixels) that the resulting assets must have. craft\elements\db\AssetQuery
$with string, array, null The eager-loading declaration craft\elements\db\ElementQuery
$withStructure boolean, null Whether element structure data should automatically be left-joined into the query. craft\elements\db\ElementQuery
$withTransforms string, array, null The asset transform indexes that should be eager-loaded, if they exist craft\elements\db\AssetQuery
Protected Properties
Property Type Description Defined By
$defaultOrderBy array The default orderBy() value to use if orderBy() is empty but not null. craft\elements\db\ElementQuery
Public Methods
Method Description Defined By
__call() Calls the named method which is not a class method. craft\elements\db\ElementQuery
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor craft\elements\db\ElementQuery
__get() Returns the value of a component property. craft\elements\db\ElementQuery
__isset() Checks if a property is set, i.e. defined and not null. craft\elements\db\ElementQuery
__set() Sets the value of a component property. craft\elements\db\AssetQuery
__toString() Returns the SQL representation of Query yii\db\Query
__unset() Sets an object property to null. yii\base\BaseObject
addGroupBy() Adds additional group-by columns to the existing ones. yii\db\Query
addOrderBy() Adds additional ORDER BY columns to the query. yii\db\QueryTrait
addParams() Adds additional parameters to be bound to the query. yii\db\Query
addSelect() Add more columns to the SELECT part of the query. yii\db\Query
all() Executes the query and returns all results as an array. craft\db\Query
ancestorDist() Sets the ancestorDist() property. craft\elements\db\ElementQuery
ancestorOf() Sets the ancestorOf() property. craft\elements\db\ElementQuery
andFilterCompare() Adds a filtering condition for a specific column and allow the user to choose a filter operator. yii\db\Query
andFilterHaving() Adds an additional HAVING condition to the existing one but ignores empty operands. yii\db\Query
andFilterWhere() Adds an additional WHERE condition to the existing one but ignores empty operands. yii\db\QueryTrait
andHaving() Adds an additional HAVING condition to the existing one. yii\db\Query
andWhere() Adds an additional WHERE condition to the existing one. yii\db\QueryTrait
archived() Sets the archived() property. craft\elements\db\ElementQuery
asArray() Sets the asArray() property. craft\elements\db\ElementQuery
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
average() Returns the average of the specified column values. yii\db\Query
batch() Starts a batch query. yii\db\Query
behaviors() Returns a list of behaviors that this component should behave as. craft\db\Query
cache() Enables query cache for this Query. yii\db\Query
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
className() Returns the fully qualified name of this class. yii\base\BaseObject
column() Executes the query and returns the first column of the result. craft\db\Query
count() Returns the number of records. craft\elements\db\ElementQuery
create() Creates a new Query object and copies its property values from an existing one. yii\db\Query
createCommand() Creates a DB command that can be used to execute this query. yii\db\Query
criteriaAttributes() Returns the query's criteria attributes. craft\elements\db\ElementQuery
dateCreated() Sets the dateCreated() property. craft\elements\db\ElementQuery
dateModified() Sets the dateModified() property. craft\elements\db\AssetQuery
dateUpdated() Sets the dateUpdated() property. craft\elements\db\ElementQuery
descendantDist() Sets the descendantDist() property. craft\elements\db\ElementQuery
descendantOf() Sets the descendantOf() property. craft\elements\db\ElementQuery
detachBehavior() Detaches a behavior from the component. yii\base\Component
detachBehaviors() Detaches all behaviors from the component. yii\base\Component
distinct() Sets the value indicating whether to SELECT DISTINCT or not. yii\db\Query
each() Starts a batch query and retrieves data row by row. yii\db\Query
emulateExecution() Sets whether to emulate query execution, preventing any interaction with data storage. yii\db\QueryTrait
enabledForSite() Sets the enabledForSite() property. craft\elements\db\ElementQuery
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. yii\base\Component
exists() Returns a value indicating whether the query result contains any row of data. craft\db\Query
extraFields() Returns the list of fields that can be expanded further and returned by toArray(). yii\base\ArrayableTrait
fields() Returns the list of fields that should be returned by default by toArray() when no specific fields are specified. yii\base\ArrayableTrait
filename() Sets the filename() property. craft\elements\db\AssetQuery
filterHaving() Sets the HAVING part of the query but ignores empty operands. yii\db\Query
filterWhere() Sets the WHERE part of the query but ignores empty operands. yii\db\QueryTrait
find() Returns all elements that match the criteria. craft\elements\db\ElementQuery
first() Returns the first element that matches the criteria. craft\elements\db\ElementQuery
fixedOrder() Sets the fixedOrder() property. craft\elements\db\ElementQuery
folderId() Sets the folderId() property. craft\elements\db\AssetQuery
from() Sets the FROM part of the query. yii\db\Query
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getCachedResult() Returns the resulting elements set by setCachedResult(), if the criteria params haven’t changed since then. craft\elements\db\ElementQuery
getCriteria() Returns an array of the current criteria attribute values. craft\elements\db\ElementQuery
getIterator() Required by the IteratorAggregate interface. craft\elements\db\ElementQuery
getRawSql() Shortcut for createCommand()->getRawSql(). craft\db\Query
getTablesUsedInFrom() Returns table names used in from() indexed by aliases. yii\db\Query
groupBy() Sets the GROUP BY part of the query. yii\db\Query
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event. yii\base\Component
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
having() Sets the HAVING part of the query. yii\db\Query
height() Sets the height() property. craft\elements\db\AssetQuery
id() Sets the id() property. craft\elements\db\ElementQuery
ids() Executes the query and returns the IDs of the resulting elements. craft\elements\db\ElementQuery
inReverse() Sets the inReverse() property. craft\elements\db\ElementQuery
includeSubfolders() Sets the includeSubfolders() property. craft\elements\db\AssetQuery
indexBy() Sets the indexBy() property. yii\db\QueryTrait
init() Initializes the object. craft\db\Query
innerJoin() Appends an INNER JOIN part to the query. yii\db\Query
isJoined() Returns whether a given table has been joined in this query. craft\db\Query
join() Appends a JOIN part to the query. yii\db\Query
kind() Sets the kind() property. craft\elements\db\AssetQuery
last() Returns the last element that matches the criteria. craft\elements\db\ElementQuery
leftJoin() Appends a LEFT OUTER JOIN part to the query. yii\db\Query
level() Sets the level() property. craft\elements\db\ElementQuery
limit() Sets the LIMIT part of the query. yii\db\QueryTrait
locale() Sets the site() property. craft\elements\db\ElementQuery
localeEnabled() Sets the enabledForSite() property. craft\elements\db\ElementQuery
max() Returns the maximum of the specified column values. yii\db\Query
min() Returns the minimum of the specified column values. yii\db\Query
nextSiblingOf() Sets the nextSiblingOf() property. craft\elements\db\ElementQuery
noCache() Disables query cache for this Query. yii\db\Query
nth() Executes the query and returns a single row of result at a given offset. craft\db\Query
off() Detaches an existing event handler from this component. yii\base\Component
offset() Sets the OFFSET part of the query. yii\db\QueryTrait
offsetExists() Required by the ArrayAccess interface. craft\elements\db\ElementQuery
offsetGet() Required by the ArrayAccess interface. craft\elements\db\ElementQuery
offsetSet() Required by the ArrayAccess interface. craft\elements\db\ElementQuery
offsetUnset() Required by the ArrayAccess interface. craft\elements\db\ElementQuery
on() Attaches an event handler to an event. yii\base\Component
one() Executes the query and returns a single row of result. craft\db\Query
orFilterHaving() Adds an additional HAVING condition to the existing one but ignores empty operands. yii\db\Query
orFilterWhere() Adds an additional WHERE condition to the existing one but ignores empty operands. yii\db\QueryTrait
orHaving() Adds an additional HAVING condition to the existing one. yii\db\Query
orWhere() Adds an additional WHERE condition to the existing one. yii\db\QueryTrait
order() Sets the orderBy() property. craft\elements\db\ElementQuery
orderBy() Sets the ORDER BY part of the query. yii\db\QueryTrait
pairs() Executes the query and returns the first two columns in the results as key/value pairs. craft\db\Query
params() Sets the parameters to be bound to the query. yii\db\Query
populate() Converts the raw query results into the format as specified by this query. craft\elements\db\AssetQuery
positionedAfter() Sets the positionedAfter() property. craft\elements\db\ElementQuery
positionedBefore() Sets the positionedBefore() property. craft\elements\db\ElementQuery
prepare() Prepares for building SQL. craft\elements\db\ElementQuery
prevSiblingOf() Sets the prevSiblingOf() property. craft\elements\db\ElementQuery
ref() Sets the ref() property. craft\elements\db\ElementQuery
relatedTo() Sets the relatedTo() property. craft\elements\db\ElementQuery
rightJoin() Appends a RIGHT OUTER JOIN part to the query. yii\db\Query
scalar() Returns the query result as a scalar value. craft\db\Query
search() Sets the search() property. craft\elements\db\ElementQuery
select() Sets the SELECT part of the query. yii\db\Query
setCachedResult() Sets the resulting elements. craft\elements\db\ElementQuery
siblingOf() Sets the siblingOf() property. craft\elements\db\ElementQuery
site() Sets the siteId() property based on a given site(s)’s handle. craft\elements\db\ElementQuery
siteId() Sets the siteId() property. craft\elements\db\ElementQuery
size() Sets the size() property. craft\elements\db\AssetQuery
slug() Sets the slug() property. craft\elements\db\ElementQuery
source() Sets the volumeId() property based on a given volume(s)’s handle(s). craft\elements\db\AssetQuery
sourceId() Sets the volumeId() property. craft\elements\db\AssetQuery
status() Sets the status() property. craft\elements\db\ElementQuery
structureId() Sets the structureId() property. craft\elements\db\ElementQuery
sum() Returns the sum of the specified column values. yii\db\Query
title() Sets the title() property. craft\elements\db\ElementQuery
toArray() Converts the model into an array. yii\base\ArrayableTrait
total() Returns the total elements that match the criteria. craft\elements\db\ElementQuery
trigger() Triggers an event. yii\base\Component
uid() Sets the uid() property. craft\elements\db\ElementQuery
union() Appends a SQL statement using UNION operator. yii\db\Query
uri() Sets the uri() property. craft\elements\db\ElementQuery
volume() Sets the volumeId() property based on a given volume(s)’s handle(s). craft\elements\db\AssetQuery
volumeId() Sets the volumeId() property. craft\elements\db\AssetQuery
where() Sets the WHERE part of the query. yii\db\QueryTrait
width() Sets the width() property. craft\elements\db\AssetQuery
with() Sets the with() property. craft\elements\db\ElementQuery
withStructure() Sets the withStructure() property. craft\elements\db\ElementQuery
withTransforms() Sets the withTransforms() property. craft\elements\db\AssetQuery
Protected Methods
Method Description Defined By
afterPrepare() This method is called at the end of preparing an element query for the query builder. craft\elements\db\ElementQuery
beforePrepare() This method is called at the beginning of preparing an element query for the query builder. craft\elements\db\AssetQuery
cleanUpTableNames() Clean up table names and aliases Both aliases and names are enclosed into {{ and }}. yii\db\Query
customFields() Returns the fields that should take part in an upcoming elements query. craft\elements\db\ElementQuery
extractFieldsFor() Extract nested fields from a fields collection for a given root field Nested fields are separated with dots (.). e.g: "item.id" The previous example would extract "id". yii\base\ArrayableTrait
extractRootFields() Extracts the root field names from nested fields. yii\base\ArrayableTrait
filterCondition() Removes empty operands from the given query condition. yii\db\QueryTrait
getUnaliasedColumnsFromSelect() yii\db\Query
getUniqueColumns() Returns unique column names excluding duplicates. yii\db\Query
isEmpty() Returns a value indicating whether the give value is "empty". yii\db\QueryTrait
joinElementTable() Joins in a table with an id column that has a foreign key pointing to craft_elements.id. craft\elements\db\ElementQuery
normalizeOrderBy() Normalizes format of ORDER BY data. yii\db\QueryTrait
queryScalar() Queries a scalar value by setting select() first. craft\db\Query
resolveFields() Determines which fields can be returned by toArray(). yii\base\ArrayableTrait
setCommandCache() Sets $command cache, if this query has enabled caching. yii\db\Query
statusCondition() Returns the condition that should be applied to the element query for a given status. craft\elements\db\ElementQuery
Events
Event Type Description Defined By
EVENT_AFTER_POPULATE_ELEMENT craft\events\PopulateElementEvent The event that is triggered after an element is populated. craft\elements\db\ElementQuery
EVENT_AFTER_PREPARE \craft\elements\db\Event An event that is triggered at the end of preparing an element query for the query builder. craft\elements\db\ElementQuery
EVENT_BEFORE_PREPARE \craft\elements\db\Event An event that is triggered at the beginning of preparing an element query for the query builder. craft\elements\db\ElementQuery
EVENT_DEFINE_BEHAVIORS craft\events\DefineBehaviorsEvent The event that is triggered when defining the class behaviors craft\db\Query
EVENT_INIT yii\base\Event The event that is triggered after the query's init cycle craft\db\Query

Property Details

$dateModified public property #

The Date Modified that the resulting assets must have.

public mixed $dateModified null

$filename public property #

The filename(s) that the resulting assets must have.

public string, string[], null $filename null

$folderId public property #

The asset folder ID(s) that the resulting assets must be in.

public integer, integer[], null $folderId null

$height public property #

The height (in pixels) that the resulting assets must have.

public integer, null $height null

$includeSubfolders public property #

Whether the query should search the subfolders of folderId().

public boolean $includeSubfolders false

$kind public property #

The file kind(s) that the resulting assets must be.

public string, string[], null $kind null

$size public property #

The size (in bytes) that the resulting assets must have.

public integer, null $size null

$volumeId public property #

The volume ID(s) that the resulting assets must be in.

public integer, integer[], null $volumeId null

$width public property #

The width (in pixels) that the resulting assets must have.

public integer, null $width null

$withTransforms public property #

The asset transform indexes that should be eager-loaded, if they exist

public string, array, null $withTransforms null

Method Details

__set() public method #

Sets the value of a component property.

This method will check in the following order and act accordingly:

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $component->property = $value;.

public void __set ( $name, $value )
$name string The property name or the event name
$value mixed The property value
throws yii\base\UnknownPropertyException if the property is not defined
throws yii\base\InvalidCallException if the property is read-only.

beforePrepare() protected method #

This method is called at the beginning of preparing an element query for the query builder.

The main Query object being prepared for the query builder is available via $query. The subselect’s Query object being prepared is available via $subQuery. The role of the subselect query is to apply conditions to the query and narrow the result set down to just the elements that should actually be returned. The role of the main query is to join in any tables that should be included in the results, and select all of the columns that should be included in the results.

protected boolean beforePrepare ( )
return boolean Whether the query should be prepared and returned to the query builder. If false, the query will be cancelled and no results will be returned.

dateModified() public method #

Sets the dateModified() property.

public static dateModified ( $value )
$value mixed The property value
return static Self reference

filename() public method #

Sets the filename() property.

public static filename ( $value )
$value string, string[], null The property value
return static Self reference

folderId() public method #

Sets the folderId() property.

public static folderId ( $value )
$value integer, integer[], null The property value
return static Self reference

height() public method #

Sets the height() property.

public static height ( \craft\elements\db\int $value null )
$value integer, null The property value
return static Self reference

includeSubfolders() public method #

Sets the includeSubfolders() property.

public static includeSubfolders ( \craft\elements\db\bool $value true )
$value boolean The property value (defaults to true)
return static Self reference

kind() public method #

Sets the kind() property.

public static kind ( $value )
$value string, string[], null The property value
return static Self reference

populate() public method #

Converts the raw query results into the format as specified by this query.

This method is internally used to convert the data fetched from database into the format as required by this query.

public craft\base\ElementInterface[], array populate ( $rows )
$rows array The raw query result from database
return craft\base\ElementInterface[], array The resulting elements.

size() public method #

Sets the size() property.

public static size ( \craft\elements\db\int $value null )
$value integer, null The property value
return static Self reference

source() public method #

Deprecated since Craft 3.0. Use volume() instead.

Sets the volumeId() property based on a given volume(s)’s handle(s).

public static source ( $value )
$value string, string[], craft\base\Volume The property value
return static Self reference

sourceId() public method #

Deprecated since Craft 3.0. Use volumeId() instead.

Sets the volumeId() property.

public static sourceId ( $value )
$value integer, integer[] The property value
return static Self reference

volume() public method #

Sets the volumeId() property based on a given volume(s)’s handle(s).

public static volume ( $value )
$value string, string[], craft\base\Volume, null The property value
return static Self reference

volumeId() public method #

Sets the volumeId() property.

public static volumeId ( $value )
$value integer, integer[], null The property value
return static Self reference

width() public method #

Sets the width() property.

public static width ( \craft\elements\db\int $value null )
$value integer, null The property value
return static Self reference

withTransforms() public method #

Sets the withTransforms() property.

public self withTransforms ( array $value null )
$value string, array, null The transforms to include.
return self The query object itself