我被 cakePHP 的一个奇怪行为困住了。当我找到('all'); 如果我采用两个相互恢复的条件,我的数组将结果分组......
示例:第一个请求条件数组:
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()
),
ETC
当我提出更多条件时:条件数组:
array(
(int) 1 => '1',
'Defect.status_id' => '1',
'found_by_user_id' => '99',
'Defect.status_isopen' => (int) 1
)
结果bug... Cake group 两个参数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...
注意:我使用可包含的行为。我的 find('all'); 指向一个视图表。地位是我的榜样之一。
提前致谢 !!
编辑:这是我的分页查询:
$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