PHP Трейт yii\db\ActiveRelationTrait

С версии: 2.0
Автор: Qiang Xue ([email protected])
Автор: Carsten Brandt ([email protected])
Показать файл Открыть проект

Открытые свойства

Свойство Тип Описание
$inverseOf the name of the relation that is the inverse of this relation. For example, an order has a customer, which means the inverse of the "customer" relation is the "orders", and the inverse of the "orders" relation is the "customer". If this property is set, the primary record(s) will be referenced through the specified relation. For example, $customer->orders[0]->customer and $customer will be the same object, and accessing the customer of an order will not trigger new DB query. This property is only used in relational context.
$link the columns of the primary and foreign tables that establish a relation. The array keys must be columns of the table for this relation, and the array values must be the corresponding columns from the primary table. Do not prefix or quote the column names as this will be done automatically by Yii. This property is only used in relational context.
$multiple whether this query represents a relation to more than one record. This property is only used in relational context. If true, this relation will populate all query results into AR instances using [[Query::all()|all()]]. If false, only the first row of the results will be retrieved using [[Query::one()|one()]].
$primaryModel the primary model of a relational query. This is used only in lazy loading with dynamic query options.
$via the query associated with the junction table. Please call ActiveRelationTrait::via to set this property instead of directly setting it. This property is only used in relational context.

Открытые методы

Метод Описание
__clone ( ) Clones internal objects.
findFor ( string $name, yii\db\ActiveRecordInterface | BaseActiveRecord $model ) : mixed Finds the related records for the specified primary record.
inverseOf ( string $relationName ) Sets the name of the relation that is the inverse of this relation.
populateRelation ( string $name, array &$primaryModels ) : array Finds the related records and populates them into the primary models.
via ( string $relationName, callable $callable = null ) Specifies the relation associated with the junction table.

Приватные методы

Метод Описание
addInverseRelations ( array &$result ) If applicable, populate the query's primary model into the related records' inverse relationship
buildBuckets ( array $models, array $link, array $viaModels = null, array $viaLink = null, boolean $checkMultiple = true ) : array
filterByModels ( array $models )
findJunctionRows ( array $primaryModels ) : array
getModelKey ( yii\db\ActiveRecordInterface | array $model, array $attributes ) : string
indexBuckets ( array $buckets, $indexBy ) : array Indexes buckets by column name.
normalizeModelKey ( mixed $value ) : string
populateInverseRelation ( yii\db\ActiveRecordInterface[] &$primaryModels, yii\db\ActiveRecordInterface[] $models, string $primaryName, string $name )
prefixKeyColumns ( array $attributes ) : array

Описание методов

__clone() публичный Метод

Clones internal objects.
public __clone ( )

findFor() публичный Метод

This method is invoked when a relation of an ActiveRecord is being accessed in a lazy fashion.
public findFor ( string $name, yii\db\ActiveRecordInterface | BaseActiveRecord $model ) : mixed
$name string the relation name
$model yii\db\ActiveRecordInterface | BaseActiveRecord the primary model
Результат mixed the related record(s)

inverseOf() публичный Метод

For example, an order has a customer, which means the inverse of the "customer" relation is the "orders", and the inverse of the "orders" relation is the "customer". If this property is set, the primary record(s) will be referenced through the specified relation. For example, $customer->orders[0]->customer and $customer will be the same object, and accessing the customer of an order will not trigger a new DB query. Use this method when declaring a relation in the ActiveRecord class: php public function getOrders() { return $this->hasMany(Order::className(), ['customer_id' => 'id'])->inverseOf('customer'); }
public inverseOf ( string $relationName )
$relationName string the name of the relation that is the inverse of this relation.

populateRelation() публичный Метод

Finds the related records and populates them into the primary models.
public populateRelation ( string $name, array &$primaryModels ) : array
$name string the relation name
$primaryModels array primary models
Результат array the related models

via() публичный Метод

Use this method to specify a pivot record/table when declaring a relation in the ActiveRecord class: php class Order extends ActiveRecord { public function getOrderItems() { return $this->hasMany(OrderItem::className(), ['order_id' => 'id']); } public function getItems() { return $this->hasMany(Item::className(), ['id' => 'item_id']) ->via('orderItems'); } }
public via ( string $relationName, callable $callable = null )
$relationName string the relation name. This refers to a relation declared in [[primaryModel]].
$callable callable a PHP callback for customizing the relation associated with the junction table. Its signature should be `function($query)`, where `$query` is the query to be customized.

Описание свойств

$inverseOf публичное свойство

the name of the relation that is the inverse of this relation. For example, an order has a customer, which means the inverse of the "customer" relation is the "orders", and the inverse of the "orders" relation is the "customer". If this property is set, the primary record(s) will be referenced through the specified relation. For example, $customer->orders[0]->customer and $customer will be the same object, and accessing the customer of an order will not trigger new DB query. This property is only used in relational context.
См. также: inverseOf()
public $inverseOf

$multiple публичное свойство

whether this query represents a relation to more than one record. This property is only used in relational context. If true, this relation will populate all query results into AR instances using [[Query::all()|all()]]. If false, only the first row of the results will be retrieved using [[Query::one()|one()]].
public $multiple

$primaryModel публичное свойство

the primary model of a relational query. This is used only in lazy loading with dynamic query options.
public $primaryModel

$via публичное свойство

the query associated with the junction table. Please call ActiveRelationTrait::via to set this property instead of directly setting it. This property is only used in relational context.
См. также: via()
public $via