簡體   English   中英

無法從cakephp分頁連接中獲得不同的行

[英]cant get distinct rows from cakephp pagination join

我無法從此搜索中獲得不同的學生ID行。 我沒有收到錯誤,返回的數據是正確的,因為一些學生的科目超過1個。 主題的原因是稍后包含搜索參數,因此我仍然需要聯接中的主題。 這似乎什么也沒做?'DISTINCT Student.id'

 $this->Student->recursive = -1;

        $joinoptions = array(

             array('table' => 'students_subjects',
                        'alias' => 'StudentsSubject',
                        'type' => 'LEFT',
                        'conditions' => array(
                        'Student.id=StudentsSubject.student_id',
                 )
                 ),     

           array('table' => 'guardians',
                'alias' => 'Guardian',
                'type' => 'LEFT',
                'conditions' => array(
                'Student.guardian_id=Guardian.id',
                 )
                 ),
           array('table' => 'subjects',
                        'alias' => 'Subject',
                        'type' => 'LEFT',
                        'conditions' => array(
                        'StudentsSubject.subject_id=Subject.id',
                 )
                 ),           

            );

         $fieldoptions = array('DISTINCT Student.id',' Student.last_name','Student.first_name',
             'Guardian.guardian_last_name','Guardian.guardian_first_name','Guardian.id','Guardian.guardian_mobile','Guardian.guardian_email',
                     'Subject.name','Subject.id'
             );

               $condionoptions= array(' Student.student_enq !=' => true,'Student.student_inactive !=' => true,'Student.tutor_gender_preference !=' => '', 

                      'AND' =>array(
                      array('OR' => array(
                                   array('Student.first_name LIKE'  => '%' . $searchFirstName  . '%'),
                                   array('Guardian.guardian_first_name LIKE'  => '%' . $searchFirstName  . '%'),

                        )),
                          /*
                      array('OR' => array(
                                   array('Student.last_name LIKE'  => '%' . $searchLastName  . '%'),
                                   array('Guardian.guardian_last_name LIKE'  => '%' . $searchLastName  . '%'),

                        )) ,
                        array('OR' => array(
                                   array('Student.student_mobile LIKE'  => '%' . $searchmobile  . '%'),
                                   array('Guardian.guardian_mobile LIKE'  => '%' . $searchmobile   . '%'),

                        ))
                         */ 
                        ) 
                       );


          $orderoptions =array('Student.first_name'=> 'ASC');             


        $this->Paginator->settings = array(
         'conditions'=> $condionoptions,
               'fields'=>$fieldoptions,
                'joins'=> $joinoptions,
                'limit' => 25,
        'recursive' =>-1,
                'order'=> $orderoptions,
               'page'=>1
               ); 

          $students= $this->Paginator->paginate('Student');  

樣本輸出

(int) 1 => array(
        'Student' => array(
            'id' => '216',
            'last_name' => 'Nipps',
            'first_name' => 'Aaron'
        ),
        'Guardian' => array(
            'guardian_last_name' => 'Nipps',
            'guardian_first_name' => 'Audet',
            'id' => '216',
            ..
        ),
        'Subject' => array(
            'name' => 'English: Year 7 - 10',
            'id' => '9'
        )
    ),
    (int) 2 => array(
        'Student' => array(
            'id' => '216',
            'last_name' => 'Nipps',
            'first_name' => 'Aaron'
        ),
        'Guardian' => array(
            'guardian_last_name' => 'Nipps',
            'guardian_first_name' => 'Audet',
            'id' => '216',
            ..'
        ),
        'Subject' => array(
            'name' => 'Maths: Year 7 - 10',
            'id' => '16'
        )
    ),

CakePHP:如何使分頁器組件使用不同的計數?

EDIT
  (int) 1 => array(
            'Student' => array(
                'id' => '216', //Only want ids to appear once and not twice as above, The above example has the id 216 appearing 2 times
                'last_name' => 'Nipps',
                'first_name' => 'Aaron'
            ),
            'Guardian' => array(
                'guardian_last_name' => 'Nipps',
                'guardian_first_name' => 'Audet',
                'id' => '216',
                ..
            ),
            'Subject' => array(
                'name' => 'English: Year 7 - 10',
                'id' => '9'
            )
        ),

我需要添加組,這可以解決問題

 $this->Paginator->settings = array(
         'conditions'=> $condionoptions,
               'fields'=>$fieldoptions,
                'joins'=> $joinoptions,
                'group' => 'Student.id',
                'limit' => 25,
        'recursive' =>-1,
                'order'=> $orderoptions,
               'page'=>1
               ); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM