cakephp链接模型没有显示在hasmany

时间:2014-07-01 10:44:02

标签: cakephp model model-associations

我在cakephp中有三个模型

//Union
  public $hasMany = 'Member';

//Member
 public $hasOne = 'Post';

其中post包含帖子名称

现在问题出在我使用的时候:

$this->Union->findById(1);
在Union控制器中,它显示链接的成员但不显示帖子的名称

[Union] => Array
        (
            [id] => 1
            [Name] => Dawa vyapar mandal
            [created] => 2014-03-31 14:08:12
        )

    [Member] => Array
        (
            [0] => Array
                (
                    [id] => 1
                    [Name] => Ashish
                    [post_id] => 1
                    [union_id] => 1
                    [created] => 2014-03-31 14:11:02
                )

            [1] => Array
                (
                    [id] => 2
                    [Name] => Ashu
                    [post_id] => 1
                    [union_id] => 1
                    [created] => 2014-07-01 15:01:15
                )
        )
)

那么如何在Member Model中实现Post Model?

1 个答案:

答案 0 :(得分:0)

您必须使模型递归到您需要数据的级别。

在你的情况下,你需要数据到第二级,所以递归为 -

$this->Union->recursive = 2;

然后找到你的数据 -

$this->Union->findById(1)
相关问题