在cakephp中查找find()的ω
我在HABTM声明中提到:在cakephp中查找find()的ω,php,cakephp,cakephp-model,Php,Cakephp,Cakephp Model,我在HABTM声明中提到: $this->set('usergroups', $this->User->find('first', array('conditions' => array('User.id' => $this->Auth->user('id'))))); 这将通过courses\u users表获取与用户id关联的组 除了我还需要查找用户不属于的所有组之外,这个方法非常适合查找。我怎样才能得到与上述陈述相反的结果 我用“不”作为条件,它
$this->set('usergroups', $this->User->find('first', array('conditions' => array('User.id' => $this->Auth->user('id')))));
这将通过courses\u users表获取与用户id关联的组
除了我还需要查找用户不属于的所有组之外,这个方法非常适合查找。我怎样才能得到与上述陈述相反的结果
我用“不”作为条件,它仍然给了我同样的结果
谢谢 像这样的方法应该会奏效:
$user = $this->User->find('first', array(
'conditions' => array(
'User.id' => $this->Auth->user('id')
)
));
$otherGroups = $this->Group->find('all', array(
'conditions' => array(
'NOT' => array('id' => Hash::extract($user, '{n}.Group.id'))
)
));
旁注:您应该在AppModel中将
recursive
设置为-1
,而不是依赖recursive来返回额外的数据。相反,使用。类似的方法应该可以:
$user = $this->User->find('first', array(
'conditions' => array(
'User.id' => $this->Auth->user('id')
)
));
$otherGroups = $this->Group->find('all', array(
'conditions' => array(
'NOT' => array('id' => Hash::extract($user, '{n}.Group.id'))
)
));
旁注:您应该在AppModel中将
recursive
设置为-1
,而不是依赖recursive来返回额外的数据。相反,使用。这是你为每件事所用的东西,这是你为每件事所用的东西