db\ActiveQuery viaTable()

viaTable() public method

Specifies the junction table for a relational query.

Use this method to specify a junction table when declaring a relation in the yii\db\ActiveRecord class:

public function getItems()
{
    return $this->hasMany(Item::className(), ['id' => 'item_id'])
                ->viaTable('order_item', ['order_id' => 'id']);
}

See also via().

public $this viaTable ( $tableName, $link, callable $callable = null )
$tableName string

The name of the junction table.

$link array

The link between the junction table and the table associated with $primaryModel. The keys of the array represent the columns in the junction table, and the values represent the columns in the $primaryModel table.

$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.

return $this

The query object itself

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

Please login to continue.