How to change the sequence of 'joins' in CakePHP?

前端 未结 4 950
萌比男神i
萌比男神i 2020-12-03 20:21

I have the problem with the sequence of joins. The similar problem was in another question Manipulating Order of JOINS in CakePHP. The answer was to use Containable behavior

4条回答
  •  感动是毒
    2020-12-03 20:36

    public function selectdata(){
       $option= $this->Group->find('all', 
                        array(
                            'joins' =>
                                array(
                                    array(
                                        'table'=> 'user_groups',
                                        'alias'=>'g',
                                        'type'=> 'INNER',
                                        'conditions'=> array('g.group_id =Group.id ')
                                     ),
                                    array(
                                        'table'=> 'users',
                                        'alias'=>'u',
                                        'type'=> 'INNER',
                                        'conditions'=> array('u.id = g.user_id')
                                    ),
                         ),'fields'=>array('Group.name,Group.created,Group.modified,Group.status,Group.created_by,u.first_name,u.last_name'),
                           'conditions'=>array('g.group_id=Group.created_by or g.user_id=u.id')
    //                        ."'".$created_by."'"
                            )
                   ); 
                 var_dump($option);//die(); 
                   if(isset($this->params['requested']))
                   {
                           return $option;
                   }
                   $this->set('groups', $option);
    
        }
    

提交回复
热议问题