LoginSignup
17
13

More than 5 years have passed since last update.

CakePHP2 containableでrecursive=2のテーブルを取得する方法

Last updated at Posted at 2014-04-16

忘備録として
containableでrecursive=2のテーブルのレコードを取得する方法。
Model1 - Model2 - Model3と取得する場合


$data= $this->Model1->find('first', array(
    'contain' => array(
        'Model2' => array(
            'Model3',
        ),
    ),
    'conditions' => array(
        'Model1.id' => $id,
    ),
));

こうやって書けば、Model2に関連づくModel3のレコードも取得できる。
recursive=2にすると、必要のない階層のテーブルのレコードまで取得してくるので
必要なレコードだけを取ってきたい場合はこのように書けばいいね。というメモ。

17
13
0

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
17
13