CakePHP包含关键问题

时间:2013-08-21 04:41:56

标签: cakephp

您好我在我的模型上写了包含它只影响第一个记录和其他记录   包含所有不必要的记录。   我的控制器逻辑:

$findFiles['conditions']['Content.created_by'] = $curUser;  
    $findFiles['conditions']['KmpContent.is_approved'] = false;
    $findFiles['conditions']['KmpContent.is_file'] = true;      
    $findFiles['contain'] = array('Parent' => array('SectionApprover' => array('Approver')));
    $findFiles['recursive'] = 3;
    $findFiles['fields'] = array('id', 'file_path', 'url_path', 'is_approved', 'name', 'created', 'approved_by','parent_id','display_text','is_active');
    $fileData = $this->KmpContent->find('all', $findFiles);

数组详细信息如下

 0 => 
array (
'KmpContent' => 
array (
  'id' => '881',
  'file_path' => '/uploads/test_file_for_multiple_approvers_backend_validations.docx',
  'url_path' => '/uploads/test_file_for_multiple_approvers_backend_validations.docx',
  'is_approved' => '0',
  'name' => 'file_test_file_for_multiple_approvers_backend_validations.docx',
  'created' => '2013-08-20 11:49:58',
  'approved_by' => NULL,
  'parent_id' => '143',
  'display_text' => 'test file for multiple approvers',
  'is_active' => '1',
),
'Parent' => 
array (
  'id' => '143',
  'name' => 'sct_Services.html',
  'display_text' => 'Services',
  'Parent' => 
  array (
  ),
  'Uploader' => 
  array (
  ),
  'SectionApprover' => 
  array (
    0 => 
    array (
      'id' => '104',
      'kmp_content_id' => '143',
      'approver_id' => '882',
      'Approver' => 
      array (
        'id' => '882',
        'first_name' => 'Prakasha',
        'last_name' => 'Matte',
      ),
    ),
    1 => 
    array (
      'id' => '256',
      'kmp_content_id' => '143',
      'approver_id' => '1168',
      'Approver' => 
      array (
        'id' => '1168',
        'first_name' => 'Rima Roy',
        'last_name' => 'Chowdhury',
      ),
    ),
    2 => 
    array (
      'id' => '257',
      'kmp_content_id' => '143',
      'approver_id' => '1171',
      'Approver' => 
      array (
        'id' => '1171',
        'first_name' => 'Durga Venkatesh',
        'last_name' => 'Sambhani',
      ),
    ),
    3 => 
    array (
      'id' => '258',
      'kmp_content_id' => '143',
      'approver_id' => '1172',
      'Approver' => 
      array (
        'id' => '1172',
        'first_name' => 'Gowtham Babu',
        'last_name' => 'Tummala',
      ),
    ),
    4 => 
    array (
      'id' => '259',
      'kmp_content_id' => '143',
      'approver_id' => '889',
      'Approver' => 
      array (
        'id' => '889',
        'first_name' => 'Sandeep',
        'last_name' => 'Pathuri',
      ),
    ),
  ),
),
'SectionApprover' => 
array (
),
),
1 => 
 array (
'KmpContent' => 
array (
  'id' => '882',
  'file_path' => '/uploads/test_file_for_ma_contentcontroller_save.txt',
  'url_path' => '/uploads/test_file_for_ma_contentcontroller_save.txt',
  'is_approved' => '0',
  'name' => 'file_test_file_for_ma_contentcontroller_save.txt',
  'created' => '2013-08-20 11:54:15',
  'approved_by' => NULL,
  'parent_id' => '28',
  'display_text' => 'test file for MA',
  'is_active' => '1',
),
'Parent' => 
array (
  'id' => '28',
  'name' => 'sct_domain.html',
  'display_text' => 'Domains',
  'Parent' => 
  array (
  ),
  'Uploader' => 
  array (
  ),
  'SectionApprover' => 
  array (
    0 => 
    array (
      'id' => '26',
      'kmp_content_id' => '28',
      'approver_id' => '467',
      'KmpContent' => 
      array (
        'id' => '28',
        'name' => 'sct_domain.html',
        'description' => NULL,
        'page_title' => 'IVV Knowledge Portal :: mckesson :: domain',
        'display_logo_path' => '../images/domains.png',
        'display_text' => 'Domains',
        'top_logo_path' => '/mckesson_ban.jpg',
        'top_logo_url' => 'http://www.mckesson.com/en_us/McKesson.com/',
        'header_text' => 'Domains',
        'header_desc' => NULL,
        'header_logo_path' => '',
        'is_section' => '1',
        'url_path' => '/university/mckesson/domains.html',
        'can_upload_files' => '1',
        'is_file' => '0',
        'file_path' => NULL,
        'display_order' => '1',
        'aco_path' => '',
        'menu_name' => 'mckesson',
        'view_path' => 'download_files',
        'is_approved' => '1',
        'parent_id' => '11',
        'is_active' => '1',
        'created' => '2013-06-22 21:18:27',
        'created_by' => NULL,
        'modified' => '2013-06-22 21:21:01',
        'approved_by' => NULL,
      ),
      'Approver' => 
      array (
        'id' => '467',
        'first_name' => 'Nageswara Rao',
        'last_name' => 'Menda',
      ),
    ),
  ),
),
'SectionApprover' => 
array (
),
),

我不希望kmpContent在sectionapprovers中用于所有记录

1 个答案:

答案 0 :(得分:0)

如果您将语句格式化为

,该怎么办?
$fileData = $this->KmpContent->find('all', array(
    'conditions' => array(
        'KmpContent.created_by' => $curUser,
        'KmpContent.is_approved' => false,
        'KmpContent.is_file' => true,
    ),
    'contain' => array(
        'Parent' => array(
            'SectionApprover' => array(
                'Approver'
            )
        )
    ),
    'recursive' => 3, // though you don't need to set recursive with contain
    'fields' => array('id', 'file_path', 'url_path', 'is_approved', 'name', 'created', 'approved_by','parent_id','display_text','is_active')    
));