0

我希望我的查询为:

$conditions = array(
                        'ManageTrackby.trackby_num NOT LIKE' => '%n/a%',
                        'Balancesheet.subscriber_id' => $_SESSION['Auth']['User']['subscriber_id'],
                        'Balancesheet.show_id' => $this->Session->read('openshowid'),
                        'OR' => array('Balancesheet.season_id' => $season_id,  'Balancesheet.season_id is null'),
                        'OR' => array('Balancesheet.episode_id'=> $episode_id, 'Balancesheet.episode_id is null')
                    );

它在这里跳过最后一个OR选项并给出以下结果:

Array
(
[ManageTrackby.trackby_num NOT LIKE] => %n/a%
[Balancesheet.subscriber_id] => 105
[Balancesheet.show_id] => 56
[OR] => Array
    (
        [Balancesheet.episode_id] => 86
        [0] => Balancesheet.episode_id is null
    )

)

在这里,它错过SEASON_ID了条件,知道为什么吗?

请指导我!

4

2 回答 2

0

试试这个。如果您想要所有第一个条件,加上第二个条件中的一个或,那么您将需要 AND 数组中的 OR。对于复杂的发现,请在此页面上查找信息http://book.cakephp.org/2.0/en/models/retrieving-your-data.html

$conditions = array(
   'AND' => array(
                  'ManageTrackby.trackby_num NOT LIKE' => '%n/a%',
                  'Balancesheet.subscriber_id' => $_SESSION['Auth']['User']['subscriber_id'],
                  'Balancesheet.show_id' => $this->Session->read('openshowid')
            )
   'OR' => array(
    array('Balancesheet.season_id' => $season_id,  'Balancesheet.season_id is null'),
            array('Balancesheet.episode_id'=> $episode_id, 'Balancesheet.episode_id is null')
            )
               )
于 2012-10-26T13:18:51.900 回答
0

您的数组设置 OR 元素两次。将两个 OR 语句放在各自的数组中:

  $conditions = array(
    'ManageTrackby.trackby_num NOT LIKE' => '%n/a%',
    'Balancesheet.subscriber_id' => $_SESSION['Auth']['User']['subscriber_id'],
    'Balancesheet.show_id' => $this->Session->read('openshowid'),
array('OR' => array('Balancesheet.season_id' => $season_id,  'Balancesheet.season_id is null')),
array('OR' => array('Balancesheet.episode_id'=> $episode_id, 'Balancesheet.episode_id is null'))
);
于 2012-10-26T13:45:06.630 回答