Cakephp 3如何按其他表对结果排序

Cakephp 3如何按其他表对结果排序,php,mysql,cakephp-3.0,Php,Mysql,Cakephp 3.0,我在使用Cakephp 3,我在排序结果时遇到了问题 表格 参与者 职业 事件 排序设置 每个参与者都有职业 每个事件都有排序设置 排序设置表具有 id------职业id------分类号------事件id 我想显示所有按顺序排列的参与者 参与者.事件(属于参与者.排序设置。排序编号asc我怎么做 这是我的工作 $query = $this->Participants->find('all')->contain( ['Events'=>

我在使用Cakephp 3,我在排序结果时遇到了问题

表格

  • 参与者
  • 职业
  • 事件
  • 排序设置
  • 每个参与者都有职业

    每个事件都有排序设置

    排序设置表具有

    id------职业id------分类号------事件id

    我想显示所有按顺序排列的参与者 参与者.事件(属于参与者.排序设置。排序编号asc我怎么做

    这是我的工作

     $query = $this->Participants->find('all')->contain(
                    ['Events'=>['Sorting_settings'=> ['sort' => ['Sorting_settings.sort_number' => 'asc']]],'Occupations'])
                ->where(
                    ['Participants.approved'=>false,
                    'Participants.is_sms_sent'=>false,
                    'Participants.is_cancel'=>false,
                    'Events.id'=>$eventID,
                    'gender'=>$gender])
                    ->order(['Participants.is_first_time , Sorting_settings.sort_number asc, desc,Participants.created asc '])
                     ->limit($limitEachTime);
                     foreach($query as $participantToSort){
    
                          //  debug($participantToSort);
                         echo $participantToSort->id." OC => ".$participantToSort->occupation_id."<br />";
                     }
    
    $query=$this->Participants->find('all')->contain(
    ['Events'=>['Sorting\u settings'=>['sort'=>['Sorting\u settings.sort\u number'=>'asc']],'occulations'])
    ->在哪里(
    ['Participants.approved'=>错误,
    “参与者。是否发送短信”=>错误,
    '参与者。是否取消'=>错误,
    'Events.id'=>$eventID,
    “性别”=>$SEXT])
    ->顺序(['Participants.is_first_time,Sorting_settings.sort_number asc,desc,Participants.created asc']))
    ->限额($limitEachTime);
    foreach($participantToSort查询){
    //调试($participantToSort);
    echo$participantToSort->id.“OC=>”$participantToSort->accountry_id.“
    ”; }
    我不确定这个排序号是什么,你是说顺序吗?你试过TreeBehaviors了吗?你可以创建一个菜单。我会把你的术语“参与者”改为“个人”,然后为你的活动参与者名单命名

    //sudo代码 参与者稳定

    id - person_id - parent_id - event_id
    
    //参与者控制员

     $descendants = $this->Participants
                        ->find('children', ['for' => $head])
                        ->find('threaded')   
                        ->where('event_id' => $id)
    
                        ->toArray();
    
        $this->set('participants', $descendants );
    
    //在ParticipantsTable.php中初始化

        $this->addBehavior('Tree');
    
        $this->belongsTo('ParentMenus', [
            'className' => 'Participants',
            'foreignKey' => 'parent_id'
        ]);
    
        $this->hasMany('ChildMenus', [
            'className' => 'Participants',
            'foreignKey' => 'parent_id'
        ]);
    
    在TreeBehaviors中阅读所有关于它的信息

    评论回复

    我明白了,当你说排序号时,你指的是我所说的层。不止一个人可以拥有相同的排序号,对吗

    分类号附在职业上了吗

    如果你被卡住了,一个诀窍就是向后开始

     Sort Table hasMany Occupants 
     Occupants hasMany Partcipants
     Partcipants hasMany Events
    
    //苏多

      $this->SortSettings->find('all')->order([sortnumber => 'asc' ] )->where(sort.occupants.particpants.events => $id);
    

    您好,谢谢您的回复,我的意思是我想根据该事件的排序编号对参与者进行排序,例如,如果我是事件id 7的参与者,并且我在参与者表中的职业id为5,而我在排序设置表中的职业id排序编号为3,并且其他参与者具有相同的事件id 7和他的职业id排序编号在Sorting_Settings table is 2中,我想显示按sort_number acs排序的所有参与者,所以在本例中,我应该得到第二个参与者,然后我,希望你们得到它