CakePHP找到'AND','OR'和'NOW():: date'

时间:2013-06-14 15:04:35

标签: cakephp

我试图在查找中翻译此查询,但没有成功。我的发现没有任何回报。

我的SQL(在postgresql中)

select * from projectversion where project='10003' releasedate>=now()::date or releasedate is null

我的发现

   $projectversions = $this->find('list', array(
            'recursive' => -1,
            'fields' => array('vname'),
            'conditions' => array('project' => $id_project,'releasedate >=now()::date','OR'=>array('releasedate is null'))));

任何人都可以帮助我?

1 个答案:

答案 0 :(得分:1)

您的原始SELECT似乎无效:

select * from projectversion where project='10003' releasedate>=now()::date or releasedate is null

应该是:

select * from projectversion where project='10003' AND (releasedate>=now()::date or releasedate is null)

如果是这样,您的条件应如下:

'conditions'=>array(
    'Model.project'=>10003,
    OR=>array(
        'Model.releasedate >= NOW()'
        'Model.releasedate IS NULL'
    )
)

产生:

WHERE Model.project = 10003 AND (Model.releasedate >= NOW() OR Model.releasedate IS NULL)