A
A
Acvoloe2018-06-26 08:40:49
Yii
Acvoloe, 2018-06-26 08:40:49

How to implement nested in yii2?

Hello.
How can I implement this request?

SELECT * FROM `client` WHERE `subnet` IN (SELECT `id` FROM `subnet` WHERE `bras` = 2)

using "andFilterWhere" in Yii2?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Bay, 2018-06-26
@Acvoloe

if ($this->value) 
 $query->andWhere('`subnet` IN (SELECT `id` FROM `subnet` WHERE `bras` = :bras)',['bras'=>2])

how can it be done.

A
Arman, 2018-06-26
@Arik

If there are models, then something like this:

$subnetQuery = Subnet::find();
$subnetQuery->andWhere(['bras' => 2]);

$clientQuery = Clint::find();
$clientQuery->andWehere(['in', 'subnet', $subnetQuery]);

//
$clientQuery->all();
//
$clientQuery->limit(1);
$clientQuery->one();

If not, then create instances of queries yourself and specify the necessary tables manually

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question