0
你好,我要实现我的查询OR
条件,这将是获取从另一个表中的所有记录,其中ID不存在OR
取的已记录在过去24小时内插入。选择所有记录,其中ID使用CakePHP 2.x的是不是在另一个表
此查询得到我的最后24小时
$this->Behaviors->attach('Containable');
return $this->find('all', array(
'contain' => array(
'User','UserInfo','QuestionAndTopic.Topic','UpVoteQuestion','Answer'
),
'conditions' => array(
'Question.created >=' => date('Y-m-d H:i:s', strtotime('-24 hour'))
),
'order' => 'Question.question_id DESC',
'recursive' => 0
));
结果我想要做这样的事情
$this->Behaviors->attach('Containable');
return $this->find('all', array(
'contain' => array(
'User','UserInfo','QuestionAndTopic.Topic','UpVoteQuestion','Answer'
),
'conditions' => array(
'OR' => array(
array('Question.created >=' => date('Y-m-d H:i:s', strtotime('-24 hour'))),
array('Question.question_id NOT IN ' => 'Answers'),// get results where question id is not present in answers table as foreign key
)
),
'order' => 'Question.question_id DESC',
'recursive' => 0
));
我希望你明白我的问题
阅读:https://book.cakephp.org/2.0/en/models/retrieving-your-data.html#complex-find-conditions – Kenyanke
@Kenyanke你好非常感谢你的分享。我已经理解了大部分部分,但我想知道的一件事是如何检查表中的数据。这里 array('Question.question_id NOT IN'=>'Answers'), – mynameisbutt
你的查询如何知道question_id存在于Answers中? – Kenyanke