S
S
Sergey Melnikov2016-04-08 11:24:37
Yii
Sergey Melnikov, 2016-04-08 11:24:37

How to make an additional condition in join?

Good afternoon.
Tell me how to make an additional condition in the has one connection?
Example:
return $this->hasOne(item::className(), ['name' => 'tooster', 'type' => 'yii']
This doesn't work....

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Max Khartanovych, 2016-04-10
@azazel_live

www.yiiframework.com/doc-2.0/yii-db-activequery.ht...

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

And also www.yiiframework.com/doc-2.0/guide-db-active-recor...

M
Maxim Timofeev, 2016-04-08
@webinar

1. Probably not item, but Item
2.

return $this->hasOne(Item::className(), ['name' => 'tooster'])->andWhere(['type' => 'yii'])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question