如何在CakePhp中执行此查询?
从id不在的用户中选择id(从user_details中选择userid ud join users u ON u.id = ud.userid AND ud。name
='fullname');
答案 0 :(得分:2)
获取您必须执行的确切查询:
$this->User->find(
'all',
array(
'fields' => array('User.id'),
'conditions' => array('id NOT IN (select userid from user_details ud join users u ON u.id=ud.userid AND ud.name ='fullname')'
);
但你可以简单地实现相同的结果
$this->User->find(
'all',
array(
'fields' => array('User.id'),
'conditions' => array('UserDetail.name !=' => 'fullname'),
'contain' => array('UserDetail')
);
假设您的User
模型处于真实状态(hasOne?)并且UserDetail
答案 1 :(得分:2)
最简单的方法。但不是本地的cakephp,总是试着用find()方法。
$this->User->Query("select id from users where id not in (select userid from user_details ud join users u ON u.id=ud.userid AND ud.name ='fullname')");