ScopedQuery
API reference › Soft Delete › ScopedQuery
SQL ActiveQuery that retains its soft-delete scope when alias() changes the primary table alias.
from() does not re-qualify the scope: rename the primary table with alias(), or call from()
before choosing the scope.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$asArray | bool| | Whether to return each record as an array. Default: null. | yii\ |
$behaviors read-only | array<yii\<static>> | List of behaviors attached to this component. | yii\ |
$distinct | bool | Whether to select distinct rows of data only. Default: false. | yii\ |
$emulateExecution | bool | Whether to emulate the actual query execution, returning empty or false results. Default: false. Available since 2.0.11. | yii\ |
$from | array| | The table(s) to be selected from. Default: null. | yii\ |
$groupBy | array| | How to group the query results. Default: null. | yii\ |
$having | string|yii\| | The condition to be applied in the GROUP BY clause. Default: null. | yii\ |
$indexBy | string| | The name of the column by which the query results should be indexed by. Default: null. | yii\ |
$inverseOf | string| | The name of the relation that is the inverse of this relation. Default: null. | yii\ |
$join | array| | How to join with other tables. Default: null. | yii\ |
$joinWith | array| | A list of relations that this query should be joined with Default: null. | yii\ |
$limit | int|yii\| | Maximum number of records to be returned. Default: null. | yii\ |
$link | array | The columns of the primary and foreign tables that establish a relation. Default: null. | yii\ |
$modelClass | class-string<yii\> | The name of the ActiveRecord class. Default: null. | yii\ |
$multiple | bool | Whether this query represents a relation to more than one record. Default: null. | yii\ |
$offset | int|yii\| | Zero-based offset from where the records are to be returned. Default: null. | yii\ |
$on | string| | The join condition to be used when this query is used in a relational context. Default: null. | yii\ |
$orderBy | array| | How to sort the query results. Default: null. | yii\ |
$params | array| | List of query parameter values indexed by parameter placeholders. Default: []. | yii\ |
$primaryModel | yii\| | The primary model of a relational query. Default: null. | yii\ |
$queryCacheDependency | yii\| | The dependency to be associated with the cached query result for this query Default: null. Available since 2.0.14. | yii\ |
$queryCacheDuration | int| | The default number of seconds that query results can remain valid in cache. Default: null. Available since 2.0.14. | yii\ |
$select | array| | The columns being selected. Default: null. | yii\ |
$selectOption | string| | Additional option that should be appended to the ‘SELECT’ keyword. Default: null. | yii\ |
$sql | string| | The SQL statement to be executed for retrieving AR records. Default: null. | yii\ |
$tablesUsedInFrom read-only | string[] | Table names indexed by aliases. | yii\ |
$union | array| | This is used to construct the UNION clause(s) in a SQL statement. Default: null. | yii\ |
$unionLimit | int|yii\| | Number of records to return from the complete UNION result. Default: null. Available since 22.0. | yii\ |
$unionOffset | int|yii\| | Zero-based offset for the complete UNION result. Default: null. Available since 22.0. | yii\ |
$unionOrderBy | array<int|yii\>| | How to sort the complete UNION result. Default: null. Available since 22.0. | yii\ |
$via | array| | The query associated with the junction table. Default: null. | yii\ |
$where | string|yii\| | Query condition. Default: null. | yii\ |
$with | array| | A list of relations that this query should be performed with Default: null. | yii\ |
$withQueries | array| | This is used to construct the WITH section in a SQL query. Default: null. Available since 2.0.35. | yii\ |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Constructor. | yii\ |
__call() | Calls the named method which is not a class method. | yii\ |
__clone() | Keeps the softDelete behavior of the cloned query, with its configured conditions, on the clone. | ScopedQuery |
__get() | Returns the value of a component property. | yii\ |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\ |
__set() | Sets the value of a component property. | yii\ |
__toString() | Returns the SQL representation of Query | yii\ |
__unset() | Sets a component property to be null. | yii\ |
addGroupBy() | Adds additional group-by columns to the existing ones. | yii\ |
addOrderBy() | Adds additional ORDER BY columns to the query. | yii\ |
addParams() | Adds additional parameters to be bound to the query. | yii\ |
addSelect() | Add more columns to the SELECT part of the query. | yii\ |
addUnionOrderBy() | Adds ORDER BY columns to the complete UNION result. | yii\ |
alias() | Sets the primary table alias and re-qualifies the soft-delete scope with it. | ScopedQuery |
all() | Executes query and returns all results as an array. | yii\ |
andFilterCompare() | Adds a filtering condition for a specific column and allow the user to choose a filter operator. | yii\ |
andFilterHaving() | Adds an additional HAVING condition to the existing one but ignores empty operands. | yii\ |
andFilterWhere() | Adds an additional WHERE condition to the existing one but ignores empty operands. | yii\ |
andHaving() | Adds an additional HAVING condition to the existing one. | yii\ |
andOnCondition() | Adds an additional ON condition to the existing one. | yii\ |
andWhere() | Adds an additional WHERE condition to the existing one. | yii\ |
asArray() | Sets the asArray() property. | yii\ |
attachBehavior() | Attaches a behavior to this component. | yii\ |
attachBehaviors() | Attaches a list of behaviors to the component. | yii\ |
average() | Returns the average of the specified column values. | yii\ |
batch() | The batch query result. | yii\ |
behaviors() | Declares QueryBehavior as the softDelete behavior. | ScopedQuery |
cache() | Enables query cache for this Query. | yii\ |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\ |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\ |
className() static | Returns the fully qualified name of this class. | yii\ |
column() | Executes the query and returns the first column of the result. | yii\ |
count() | Returns the number of records. | yii\ |
create() static | Creates a new Query object and copies its property values from an existing one. | yii\ |
createCommand() | Creates a DB command that can be used to execute this query. | yii\ |
deleted() | ScopedQuery | |
detachBehavior() | Detaches a behavior from the component. | yii\ |
detachBehaviors() | Detaches all behaviors from the component. | yii\ |
distinct() | Sets the value indicating whether to SELECT DISTINCT or not. | yii\ |
each() | The batch query result. | yii\ |
emulateExecution() | Sets whether to emulate query execution, preventing any interaction with data storage. | yii\ |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\ |
exists() | Returns a value indicating whether the query result contains any row of data. | yii\ |
filterDeleted() | ScopedQuery | |
filterHaving() | Sets the HAVING part of the query but ignores empty operands. | yii\ |
filterWhere() | Sets the WHERE part of the query but ignores empty operands. | yii\ |
findFor() | Finds the related records for the specified primary record. | yii\ |
findWith() | Finds records corresponding to one or multiple relations and populates them into the primary models. | yii\ |
from() | Sets the FROM part of the query. | yii\ |
getBehavior() | Returns the named behavior object. | yii\ |
getBehaviors() | Returns all behaviors attached to this component. | yii\ |
getTablesUsedInFrom() | Returns table names used in from() indexed by aliases. | yii\ |
groupBy() | Sets the GROUP BY part of the query. | yii\ |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. | yii\ |
hasMethod() | Returns a value indicating whether a method is defined. | yii\ |
hasProperty() | Returns a value indicating whether a property is defined for this component. | yii\ |
having() | Sets the HAVING part of the query. | yii\ |
indexBy() | Sets the indexBy() property. | yii\ |
init() | Initializes the object. | yii\ |
innerJoin() | Appends an INNER JOIN part to the query. | yii\ |
innerJoinWith() | Inner joins with the specified relations. | yii\ |
inverseOf() | Sets the name of the relation that is the inverse of this relation. | yii\ |
join() | Appends a JOIN part to the query. | yii\ |
joinWith() | Joins with the specified relations. | yii\ |
leftJoin() | Appends a LEFT OUTER JOIN part to the query. | yii\ |
limit() | Sets the LIMIT part of the query. | yii\ |
max() | Returns the maximum of the specified column values. | yii\ |
min() | Returns the minimum of the specified column values. | yii\ |
noCache() | Disables query cache for this Query. | yii\ |
notDeleted() | ScopedQuery | |
off() | Detaches an existing event handler from this component. | yii\ |
offset() | Sets the OFFSET part of the query. | yii\ |
on() | Attaches an event handler to an event. | yii\ |
onCondition() | Sets the ON condition for a relational query. | yii\ |
one() | Executes query and returns a single row of result. | yii\ |
orderBy() | Sets the ORDER BY part of the query. | yii\ |
orFilterHaving() | Adds an additional HAVING condition to the existing one but ignores empty operands. | yii\ |
orFilterWhere() | Adds an additional WHERE condition to the existing one but ignores empty operands. | yii\ |
orHaving() | Adds an additional HAVING condition to the existing one. | yii\ |
orOnCondition() | Adds an additional ON condition to the existing one. | yii\ |
orWhere() | Adds an additional WHERE condition to the existing one. | yii\ |
params() | Sets the parameters to be bound to the query. | yii\ |
populate() | Converts the raw query results into the format as specified by this query. | yii\ |
populateRelation() | Finds the related records and populates them into the primary models. | yii\ |
prepare() | Prepares for building SQL. | yii\ |
rightJoin() | Appends a RIGHT OUTER JOIN part to the query. | yii\ |
scalar() | Returns the query result as a scalar value. | yii\ |
select() | Sets the SELECT part of the query. | yii\ |
sum() | Returns the sum of the specified column values. | yii\ |
trigger() | Triggers an event. | yii\ |
union() | Appends a SQL statement using UNION operator. | yii\ |
unionLimit() | Sets the LIMIT part of the complete UNION result. | yii\ |
unionOffset() | Sets the OFFSET part of the complete UNION result. | yii\ |
unionOrderBy() | Sets the ORDER BY part of the complete UNION result. | yii\ |
via() | Specifies the relation associated with the junction table. | yii\ |
viaTable() | Specifies the junction table for a relational query. | yii\ |
where() | Sets the WHERE part of the query. | yii\ |
with() | Specifies the relations with which this query should be performed. | yii\ |
withDeleted() | ScopedQuery | |
withQuery() | Prepends a SQL statement using WITH syntax. | yii\ |
cleanUpTableNames() protected | Clean up table names and aliases Both aliases and names are enclosed into {{ and }}. | yii\ |
createModels() protected | Converts found rows into model instances. | yii\ |
filterCondition() protected | Removes empty operands from the given query condition. | yii\ |
getPrimaryTableName() protected | yii\ | |
getTableNameAndAlias() protected | Returns the table name and the table alias for $modelClass. | yii\ |
isEmpty() protected | Returns a value indicating whether the give value is “empty”. | yii\ |
normalizeOrderBy() protected | Normalizes format of ORDER BY data. | yii\ |
normalizeSelect() protected | Normalizes the SELECT columns passed to select() or addSelect(). | yii\ |
queryScalar() protected | Queries a scalar value by setting select() first. | yii\ |
setCommandCache() protected | Sets $command cache, if this query has enabled caching. | yii\ |
Events
Section titled “Events”| Event | Type | Description | Defined by |
|---|---|---|---|
EVENT_INIT | yii\ | An event that is triggered when the query is initialized via init(). Event name: 'init'. | yii\ |
Method details
Section titled “Method details”__clone()
Section titled “__clone() ”public function __clone(): mixedKeeps the softDelete behavior of the cloned query, with its configured conditions, on the clone.
Yii detaches every behavior from a cloned component, and behaviors() alone would declare the default one.
Returns
mixed
alias()
Section titled “alias() ”public function alias(string $alias): staticSets the primary table alias and re-qualifies the soft-delete scope with it.
Parameters
| Parameter | Type | Description |
|---|---|---|
$alias | string | Table alias, with or without {{ and }} quoting. |
Returns
static
behaviors()
Section titled “behaviors() ”public function behaviors(): array<string, class-string<yii2\extensions\softdelete\QueryBehavior>>Declares QueryBehavior as the softDelete behavior.
Returns
array<string, class-string<QueryBehavior>>
filterDeleted()
Section titled “filterDeleted() ”public function filterDeleted(mixed $deleted): $thisParameters
| Parameter | Type | Description |
|---|---|---|
$deleted | mixed |
Returns
$this