yii\db\ActiveQuery::viaTable PHP Method

viaTable() public method

Use this method to specify a junction table when declaring a relation in the ActiveRecord class: php public function getItems() { return $this->hasMany(Item::className(), ['id' => 'item_id']) ->viaTable('order_item', ['order_id' => 'id']); }
See also: via()
public viaTable ( string $tableName, array $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.
    public function viaTable($tableName, $link, callable $callable = null)
    {
        $relation = new ActiveQuery(get_class($this->primaryModel), ['from' => [$tableName], 'link' => $link, 'multiple' => true, 'asArray' => true]);
        $this->via = $relation;
        if ($callable !== null) {
            call_user_func($callable, $relation);
        }
        return $this;
    }