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

前端 未结 4 949
萌比男神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:28

    Finally I figured out how to do that:

    $this->LevelOne->unbindModel(array('belongsTo' => array('LevelTwo')));
    $this->LevelOne->find('all', array(
        'joins' => array(
              array(
                 'table' => 'level_two',
                 'alias' => 'LevelTwo',
                 'type' => 'LEFT',
                 'conditions' => array(
                      'LevelTwo.id = LevelOne.level_two_field_id'
                  )
              ),
              array(
                 'table' => 'level_three',
                 'alias' => 'LevelThree',
                 'type' => 'LEFT',
                 'conditions' => array(
                      'LevelThree.id = LevelTwo.level_three_field_id'
                  )
              )
         )
    ));
    

提交回复
热议问题