How do I write a join query across multiple tables in CakePHP?

后端 未结 6 1687
既然无缘
既然无缘 2020-11-28 07:50

can anyone tell me, how to retrieve joined result from multiple tables in cakePHP ( using cakePHP mvc architecture). For example, I have three tables to join (tbl_topics, tb

6条回答
  •  感动是毒
    2020-11-28 08:27

    You can easily set the "recursive" property on a find() query.

    $result = $this->Topic->find('all', array('recursive' => 2));
    

    Alternatively, you can use the Containable behavior in your model. Then you can use:

    $this->Topic->contain(array(
        'Item',
        'Item.Vote',
    ));
    
    $result = $this->Topic->find('all');
    

    or

    $result = $this->Topic->find('all', array(
        'contain' => array(
            'Item',
            'Item.Vote',
        ),
    ));
    

提交回复
热议问题