How do I write a subquery in cakephp
Hello everyone,
I am totally lost in implementing the following sql using cakephp ORM
SELECT *
FROM users
WHERE users.id
NOT IN ( SELECT potentials.user_id FROM potentials )
I have tried this but it is not working at all
$this->User->find('all', array(
'contain' => array(
'City' => array(
'fields' => array('id', 'name')
)
),
'conditions' => array(
'NOT IN' => array('Select user_id from potentials')
)
));
I have also tried this method mentioned on the book.cakephp.org (under the section complex find conditions) but it didn't proved of much help.
Please help me write this query in cakephp way.
Thanks
Спросил gauravgs, on 23/9/10
2 Answers
A different way from trying to run a sub query within your call would be to
find('list') the potentials user_id and use that in setting your condition to be
'conditions' => array(
'NOT' => array(
'User.id' => $postential_user_id_list,
)
)
Or, looking at it another way, if you started by finding
potentials with distinct user_id then tailoring the contain parameter on that call so that the result contained the User records you were after?
Answered by lvotuskon 23/9/10
I have already tried that link, and mentioned it in while posting my question. Please post only if you know the answer.
Thanks
gauravgs - on 23/9/10
Your Answer
You can use Creole Wiki Syntax to format your text.
Rating
0
Viewed
3119 times
Last Activity
on 23/9/10






