Answer the question
In order to leave comments, you need to log in
How to organize a link in Yii2 through a table with conditions?
In general, the query itself looks like this
SELECT * FROM `vk_users` WHERE `user_id` = 24 AND `chat_bot_clients_id` in (SELECT `id` from `chat_bot_clients` where `chat_bot_user_id` = 1)
user_id is the ID of the model that hasMany is associated with vk_users
chat_bot_user_id is the ID of the current user
How to write a communication function correctly?
Answer the question
In order to leave comments, you need to log in
It seems that this approach should work if I correctly understood what you meant by ActiveRecord:
$subQuery = chat_bot_clients::find()
->select('id')
->where(['chat_bot_user_id' => 1]);
$query = vk_users::find()
->where(['user_id' => 24])
->andWhere(['in', 'chat_bot_clients_id', $subQuery]);
$models = $query->all();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question