db\ActiveQuery onCondition()

onCondition() public method

Sets the ON condition for a relational query.

The condition will be used in the ON part when yii\db\ActiveQuery::joinWith() is called. Otherwise, the condition will be used in the WHERE part of a query.

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

public function getActiveUsers()
{
    return $this->hasMany(User::className(), ['id' => 'user_id'])
                ->onCondition(['active' => true]);
}

Note that this condition is applied in case of a join as well as when fetching the related records. Thus only fields of the related table can be used in the condition. Trying to access fields of the primary record will cause an error in a non-join-query.

public $this onCondition ( $condition, $params = [] )
$condition string|array

The ON condition. Please refer to yii\db\Query::where() on how to specify this parameter.

$params array

The parameters (name => value) to be bound to the query.

return $this

The query object itself

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

Please login to continue.