通常、containを利用するとTableクラスで関連性を定義していた場合、LEFTJOINで取得していきますが、INNERJOINしたい場合、以下のように「matching」メソッドを利用します
1 2 3 4 5 6 7 8 |
$q = $this->Users->find() ->contain('SchoolUsers.Schools') ->matching('SchoolUsers', function($q) use ($schools) { return $q ->select(['SchoolUsers.user_id']) ->where(['SchoolUsers.school_id in' => $schools]); }) ->order(['Users.id' => 'ASC']); |