db\ActiveRelationTrait inverseOf()

inverseOf() public method

Sets 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 a new DB query.

Use this method when declaring a relation in the yii\db\ActiveRecord class:

public function getOrders()
{
    return $this->hasMany(Order::className(), ['customer_id' => 'id'])->inverseOf('customer');
}
public $this inverseOf ( $relationName )
$relationName string

The name of the relation that is the inverse of this relation.

return $this

The relation object itself.

doc_Yii
2016-10-30 16:56:32
Comments
Leave a Comment

Please login to continue.