找到递归的第三级

时间:2011-03-31 03:40:25

标签: cakephp cakephp-1.3

使用:

function view($id = null) {
    if (!$id) {
        $this->Session->setFlash(__('Invalid Post', true));
        $this->redirect(array('action' => 'index'));
    }
    $this->set('post', $this->Post->read(null, $id));

}

我可以找到相关用户,但用户有个人资料。

当我列出相关用户时,我希望使用Profile Email而不是profile_id

Post $hasAndBelongsToMany Users $belongsTo Profile.

表:

用户

Posts_Users

帖子

模式。

答案:

function view($id = null) {
    if (!$id) {
        $this->Session->setFlash(__('Invalid Post', true));
        $this->redirect(array('action' => 'index'));
    }
    $this->Post->recursive =2;
    $this->set('post', $this->Post->read(null, $id));

}

1 个答案:

答案 0 :(得分:1)

你不应该使用递归2,包含你想要的东西。 http://book.cakephp.org/view/1323/Containable