I am programming using CodeIgniter 4 and I am using CodeIgniter's model as I understand it is a good practice to use it. It is a great way to do queries using one table very simple:
$this->myModel
->select('field')
->where('user_id', 1)
->findAll()
I don't even have to write the name of the table.
However, I am not able to do subqueries, in particular, I need user_id
to be read from another table:
$this->myModel
->select('field')
->whereIn('user_id', SUBQUERY)
->findAll()
SUBQUERY is select('id') from users where status='active'
.
However, this doesn't work:
$this->myModel
->select('field')
->whereIn('user_id', $this->userModel->select('id)->where('status', 'active')->findAll() )
->findAll()
Is there a way to do it with CodeIgniter's model or what is the best way to do it? Should I do the subquery with the Query Builder and mix it with the usage of the model?
Thanks!