cakephp where condition result array bugged

时间:2013-03-22 19:43:12

标签: cakephp find conditional-statements where cakephp-2.3

我被困在cakePHP的奇怪行为上。 当我找到一个('全');条件如果我采取两个恢复对方的条件,我的数组将结果分组......

示例:第一个请求 条件数组:

array(
    (int) 1 => '1',
    'found_by_user_id' => '99',
    'Defect.status_isopen' => (int) 1
)

结果:

array(
    (int) 0 => array(
        'Defect' => array(
            'id' => '14701',
            'severity_id' => '3',
            'severity_title' => 'Medium',
            'found_by_user_id' => '99',
            'found_username' => 'TB',
            'assigned_to_user_id' => '7',
            'assigned_username' => 'JB',
            'version_id' => '140',
            'version_title' => '5.2',
            'project_id' => '35',
            'project_title' => 'A4L - 5',
            'found_in_build' => '',
            'fixed_in_build' => null,
            'title' => 'MyTitle',
            'content' => 'My content',
            'status_id' => '1',
            'status_title' => 'New',
            'status_isopen' => '1',
            'location_id' => '389',
            'location_title' => 'import and export',
            'nb_followers' => '0',
            'nb_media' => '1',
            'nb_linked_objects' => '1',
            'show_stopper' => '0',
            'fixed_date' => null,
            'modified' => '2013-01-18 12:09:02',
            'created' => '2013-01-18 12:09:02'
        ),
        'Media' => array(
            (int) 0 => array(
                'id' => '2195',
                'filename' => 'boxedWarning.docx',
                'dir_name' => 'legacy',
                'defect_id' => '14701',
                'content' => 'file test',
                'user_id' => '99',
                'created' => '2013-01-18 12:09:02'
            )
        ),
        'Follow' => array(),
        'PointedObject' => array()
    ),

当我提出更多条件时: 条件数组:

array(
    (int) 1 => '1',
    'Defect.status_id' => '1',
    'found_by_user_id' => '99',
    'Defect.status_isopen' => (int) 1
)

结果错误......蛋糕组两个参数status_title,status_open ...

(int) 0 => array(
        'Defect' => array(
            'id' => '14701',
            'severity_id' => '3',
            'severity_title' => 'Medium',
            'found_by_user_id' => '99',
            'found_username' => 'TBt',
            'assigned_to_user_id' => '7',
            'assigned_username' => 'JB',
            'version_id' => '140',
            'version_title' => '5.2',
            'project_id' => '35',
            'project_title' => 'A4L - 5',
            'found_in_build' => '',
            'fixed_in_build' => null,
            'title' => 'MyTitle',
            'content' => 'My content',
            'status_id' => '1',
            'location_id' => '389',
            'location_title' => 'import and export',
            'nb_followers' => '0',
            'nb_media' => '1',
            'nb_linked_objects' => '1',
            'show_stopper' => '0',
            'fixed_date' => null,
            'modified' => '2013-01-18 12:09:02',
            'created' => '2013-01-18 12:09:02'
        ),
        'stati' => array(
            'status_title' => 'New',
            'status_isopen' => '1'
        ),
        'Media' => array(
            (int) 0 => array(
                'id' => '2195',
                'filename' => 'boxedWarning.docx',
                'dir_name' => 'legacy',
                'defect_id' => '14701',
                'content' => 'file test',
                'user_id' => '99',
                'created' => '2013-01-18 12:09:02'
            )
        ),
        'Follow' => array(),
        'PointedObject' => array()
    ),

查看stati信息......已删除子数组Stati中的Status_title和status_isopen ......

注意:我使用可包含的行为。而我的发现('全部');指向视图表。状态是我的模特之一。

提前致谢!!

编辑:这是我的分页查询:

$this->paginate = array(
    'limit' => $this->Auth->user('page_size'), 
    'recursive'=>-1,
    'contain' => array(
        'Media',
        'Follow'=> array(
            'conditions'=>array('Follow.user_id'=>$user_id), 
            'fields' => array('id','flag')
        ),
        'PointedObject' => array(
            'order'=>array('PointedObject.linked_category_id'),
            'LinkedCategory'
        )
    ),
    'conditions' => $conditions,
    'order' => $order
);

EDIT2:MySQL查询很好......

SELECT
    `Defect`.`id`, `Defect`.`severity_id`, `Defect`.`severity_title`, 
    `Defect`.`found_by_user_id`, `Defect`.`found_username`, `Defect`.`assigned_to_user_id`,
    `Defect`.`assigned_username`, `Defect`.`version_id`, `Defect`.`version_title`, 
    `Defect`.`project_id`, `Defect`.`project_title`, `Defect`.`found_in_build`, 
    `Defect`.`fixed_in_build`, `Defect`.`title`, `Defect`.`content`, 
    `Defect`.`status_id`, `Defect`.`status_title`, `Defect`.`status_isopen`, 
    `Defect`.`location_id`, `Defect`.`location_title`, `Defect`.`nb_followers`, 
    `Defect`.`nb_media`, `Defect`.`nb_linked_objects`, `Defect`.`show_stopper`, 
    `Defect`.`fixed_date`, `Defect`.`modified`, `Defect`.`created`
 FROM 
    `defects_dbo`.`defects_view` AS `Defect`
 WHERE
    `Defect`.`status_id` = 1
    AND `found_by_user_id` = 99
    AND `Defect`.`status_isopen` = 1

 ORDER BY `Defect`.`id` DESC 
 LIMIT 20

0 个答案:

没有答案