没有命名空间的类 yii yii\base yii\behaviors yii\caching yii\captcha yii\console yii\console\controllers yii\console\widgets yii\data yii\db yii\db\conditions yii\db\cubrid yii\db\cubrid\conditions yii\db\mssql yii\db\mssql\conditions yii\db\mysql yii\db\oci yii\db\oci\conditions yii\db\pgsql yii\db\sqlite yii\db\sqlite\conditions yii\di yii\filters yii\filters\auth yii\grid yii\helpers yii\i18n yii\log yii\mail yii\mutex yii\rbac yii\rest yii\test yii\validators yii\web yii\widgets

Trait yii\db\ActiveQueryTrait

实现yii\db\ActiveQuery
可用版本自2.0
源码 https://github.com/yiichina/yii2/blob/api/framework/db/ActiveQueryTrait.php

ActiveQueryTrait implements the common methods and properties for active record query classes.

公共属性

隐藏继承的属性

属性类型描述被定义在
$asArray boolean Whether to return each record as an array. yii\db\ActiveQueryTrait
$modelClass string The name of the ActiveRecord class. yii\db\ActiveQueryTrait
$with array A list of relations that this query should be performed with yii\db\ActiveQueryTrait

公共方法

隐藏继承的方法

方法描述被定义在
asArray() Sets the asArray() property. yii\db\ActiveQueryTrait
findWith() Finds records corresponding to one or multiple relations and populates them into the primary models. yii\db\ActiveQueryTrait
with() Specifies the relations with which this query should be performed. yii\db\ActiveQueryTrait

受保护的方法

隐藏继承的方法

方法描述被定义在
createModels() Converts found rows into model instances. yii\db\ActiveQueryTrait

属性详情

$asArray 公共 属性

Whether to return each record as an array. If false (default), an object of $modelClass will be created to represent each record.

public boolean $asArray null
$modelClass 公共 属性

The name of the ActiveRecord class.

public string $modelClass null
$with 公共 属性

A list of relations that this query should be performed with

public array $with null

方法详情

asArray() 公共 方法

Sets the asArray() property.

public $this asArray($value true)
$value boolean

Whether to return the query results in terms of arrays instead of Active Records.

return $this

The query object itself

createModels() 受保护 方法 (自版本 2.0.11 可用)

Converts found rows into model instances.

protected array|yii\db\ActiveRecord[] createModels($rows)
$rows array
findWith() 公共 方法

Finds records corresponding to one or multiple relations and populates them into the primary models.

public void findWith($with, &$models)
$with array

A list of relations that this query should be performed with. Please refer to with() for details about specifying this parameter.

$models array|yii\db\ActiveRecord[]

The primary models (can be either AR instances or arrays)

with() 公共 方法

Specifies the relations with which this query should be performed.

The parameters to this method can be either one or multiple strings, or a single array of relation names and the optional callbacks to customize the relations.

A relation name can refer to a relation defined in $modelClass or a sub-relation that stands for a relation of a related record. For example, orders.address means the address relation defined in the model class corresponding to the orders relation.

The following are some usage examples:

// find customers together with their orders and country
Customer::find()->with('orders', 'country')->all();
// find customers together with their orders and the orders' shipping address
Customer::find()->with('orders.address')->all();
// find customers together with their country and orders of status 1
Customer::find()->with([
    'orders' => function (\yii\db\ActiveQuery $query) {
        $query->andWhere('status = 1');
    },
    'country',
])->all();

You can call with() multiple times. Each call will add relations to the existing ones. For example, the following two statements are equivalent:

Customer::find()->with('orders', 'country')->all();
Customer::find()->with('orders')->with('country')->all();
public $this with()
return $this

The query object itself