PHP 트레잇 yii\db\ActiveRelationTrait

부터: 2.0
저자: Qiang Xue ([email protected])
저자: Carsten Brandt ([email protected])
파일 보기 프로젝트 열기: yiisoft/yii2

공개 프로퍼티들

프로퍼티 타입 설명
$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