LoginSignup
1
1

More than 5 years have passed since last update.

[cakephp3]クエリビルダでアソシエーションの条件を変える

Last updated at Posted at 2016-04-01

結合方法を変える

typeで指定する


$query = $this->Articles->find()->contain([
    'Authors' => [
        'joinType' => 'LEFT',
        'queryBuilder' => function ($q) {
            return $q->where(...); // フィルタのための完全な条件
        }
    ]
]);

ONの条件を増やす

containのwhereでvalueに結合条件を書く


$query = $this->Articles->find()->contain([
    'Authors' => function ($q) {
        return $q->where([
            'Articles.group_id = Authors.group_id',
            …
        ]);
    }
]);
1
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1