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;
}