ActiveQuery
- Type
- Class
- Namespace
- craft\db
- Inherits
- craft\db\ActiveQuery » yii\db\ActiveQuery (opens new window) » yii\db\Query (opens new window) » yii\base\Component (opens new window) » yii\base\BaseObject (opens new window)
- Implements
- yii\base\Configurable (opens new window), yii\db\ActiveQueryInterface (opens new window), yii\db\ExpressionInterface (opens new window), yii\db\QueryInterface (opens new window)
- Uses traits
- yii\db\ActiveQueryTrait (opens new window), yii\db\ActiveRelationTrait (opens new window), yii\db\QueryTrait (opens new window)
- Extended by
- craft\db\StructuredElementQuery
- Since
- 3.5.13
Active Query class.
View source (opens new window)
# Public Properties
# alias
- Type
- string (opens new window)
- Default value
null
The table alias for modelClass (opens new window).
View source (opens new window)
# Public Methods
Method | Description |
---|---|
__call() (opens new window) | Calls the named method which is not a class method. |
__clone() (opens new window) | Clones internal objects. |
__construct() (opens new window) | Constructor. |
__get() (opens new window) | Returns the value of a component property. |
__isset() (opens new window) | Checks if a property is set, i.e. defined and not null. |
__set() (opens new window) | Sets the value of a component property. |
__toString() (opens new window) | Returns the SQL representation of Query |
__unset() (opens new window) | Sets a component property to be null. |
addGroupBy() (opens new window) | Adds additional group-by columns to the existing ones. |
addOrderBy() (opens new window) | Adds additional ORDER BY columns to the query. |
addParams() (opens new window) | Adds additional parameters to be bound to the query. |
addSelect() (opens new window) | Add more columns to the SELECT part of the query. |
alias() (opens new window) | Define an alias for the table defined in modelClass (opens new window). |
all() (opens new window) | See yii\db\ActiveQueryInterface::all() (opens new window) for more info. |
andFilterCompare() (opens new window) | Adds a filtering condition for a specific column and allow the user to choose a filter operator. |
andFilterHaving() (opens new window) | Adds an additional HAVING condition to the existing one but ignores empty operands (opens new window). |
andFilterWhere() (opens new window) | Adds an additional WHERE condition to the existing one but ignores empty operands (opens new window). |
andHaving() (opens new window) | Adds an additional HAVING condition to the existing one. |
andOnCondition() (opens new window) | Adds an additional ON condition to the existing one. |
andWhere() (opens new window) | Adds an additional WHERE condition to the existing one. |
asArray() (opens new window) | Sets the asArray() (opens new window) property. |
attachBehavior() (opens new window) | Attaches a behavior to this component. |
attachBehaviors() (opens new window) | Attaches a list of behaviors to the component. |
average() (opens new window) | Returns the average of the specified column values. |
batch() (opens new window) | Starts a batch query. |
behaviors() (opens new window) | Returns a list of behaviors that this component should behave as. |
cache() (opens new window) | Enables query cache for this Query. |
canGetProperty() (opens new window) | Returns a value indicating whether a property can be read. |
canSetProperty() (opens new window) | Returns a value indicating whether a property can be set. |
className() (opens new window) | Returns the fully qualified name of this class. |
collect() | Executes the query and returns all results as a collection. |
column() (opens new window) | Executes the query and returns the first column of the result. |
count() (opens new window) | Returns the number of records. |
create() (opens new window) | Creates a new Query object and copies its property values from an existing one. |
createCommand() (opens new window) | Creates a DB command that can be used to execute this query. |
detachBehavior() (opens new window) | Detaches a behavior from the component. |
detachBehaviors() (opens new window) | Detaches all behaviors from the component. |
distinct() (opens new window) | Sets the value indicating whether to SELECT DISTINCT or not. |
each() (opens new window) | Starts a batch query and retrieves data row by row. |
emulateExecution() (opens new window) | Sets whether to emulate query execution, preventing any interaction with data storage. |
ensureBehaviors() (opens new window) | Makes sure that the behaviors declared in behaviors() (opens new window) are attached to this component. |
exists() (opens new window) | Returns a value indicating whether the query result contains any row of data. |
filterHaving() (opens new window) | Sets the HAVING part of the query but ignores empty operands (opens new window). |
filterWhere() (opens new window) | Sets the WHERE part of the query but ignores empty operands (opens new window). |
findFor() (opens new window) | Finds the related records for the specified primary record. |
findWith() (opens new window) | Finds records corresponding to one or multiple relations and populates them into the primary models. |
from() (opens new window) | Sets the FROM part of the query. |
getAlias() | Returns the table alias for modelClass (opens new window). |
getBehavior() (opens new window) | Returns the named behavior object. |
getBehaviors() (opens new window) | Returns all behaviors attached to this component. |
getTablesUsedInFrom() (opens new window) | Returns table names used in from() (opens new window) indexed by aliases. |
groupBy() (opens new window) | Sets the GROUP BY part of the query. |
hasEventHandlers() (opens new window) | Returns a value indicating whether there is any handler attached to the named event. |
hasMethod() (opens new window) | Returns a value indicating whether a method is defined. |
hasProperty() (opens new window) | Returns a value indicating whether a property is defined for this component. |
having() (opens new window) | Sets the HAVING part of the query. |
indexBy() (opens new window) | Sets the indexBy() (opens new window) property. |
init() (opens new window) | Initializes the object. |
innerJoin() (opens new window) | Appends an INNER JOIN part to the query. |
innerJoinWith() (opens new window) | Inner joins with the specified relations. |
inverseOf() (opens new window) | Sets the name of the relation that is the inverse of this relation. |
join() (opens new window) | Appends a JOIN part to the query. |
joinWith() (opens new window) | Joins with the specified relations. |
leftJoin() (opens new window) | Appends a LEFT OUTER JOIN part to the query. |
limit() (opens new window) | Sets the LIMIT part of the query. |
max() (opens new window) | Returns the maximum of the specified column values. |
min() (opens new window) | Returns the minimum of the specified column values. |
noCache() (opens new window) | Disables query cache for this Query. |
off() (opens new window) | Detaches an existing event handler from this component. |
offset() (opens new window) | Sets the OFFSET part of the query. |
on() (opens new window) | Attaches an event handler to an event. |
onCondition() (opens new window) | Sets the ON condition for a relational query. |
one() (opens new window) | See yii\db\ActiveQueryInterface::one() (opens new window) for more info. |
orFilterHaving() (opens new window) | Adds an additional HAVING condition to the existing one but ignores empty operands (opens new window). |
orFilterWhere() (opens new window) | Adds an additional WHERE condition to the existing one but ignores empty operands (opens new window). |
orHaving() (opens new window) | Adds an additional HAVING condition to the existing one. |
orOnCondition() (opens new window) | Adds an additional ON condition to the existing one. |
orWhere() (opens new window) | Adds an additional WHERE condition to the existing one. |
orderBy() (opens new window) | Sets the ORDER BY part of the query. |
params() (opens new window) | Sets the parameters to be bound to the query. |
populate() (opens new window) | Converts the raw query results into the format as specified by this query. |
populateRelation() (opens new window) | Finds the related records and populates them into the primary models. |
prepare() (opens new window) | Prepares for building SQL. |
rightJoin() (opens new window) | Appends a RIGHT OUTER JOIN part to the query. |
scalar() (opens new window) | Returns the query result as a scalar value. |
select() (opens new window) | Sets the SELECT part of the query. |
sum() (opens new window) | Returns the sum of the specified column values. |
trigger() (opens new window) | Triggers an event. |
union() (opens new window) | Appends a SQL statement using UNION operator. |
via() (opens new window) | Specifies the relation associated with the junction table. |
viaTable() (opens new window) | Specifies the junction table for a relational query. |
where() (opens new window) | Sets the WHERE part of the query. |
with() (opens new window) | Specifies the relations with which this query should be performed. |
withQuery() (opens new window) | Prepends a SQL statement using WITH syntax. |
# collect()
- Since
- 4.3.0
Executes the query and returns all results as a collection.
View source (opens new window)
Arguments
$db
(yii\db\Connection (opens new window), null (opens new window)) – The database connection used to generate the SQL statement. If null, the DB connection returned by modelClass (opens new window) will be used.
Returns
\Illuminate\Support\Collection
– A collection of the resulting records.
# getAlias()
Returns the table alias for modelClass (opens new window).
View source (opens new window)