【问题标题】:cakephp linked model not showing in hasmanycakephp链接模型未在hasmany中显示
【发布时间】:2014-07-01 10:44:01
【问题描述】:

我在 cakephp 中有三个模型

//Union
  public $hasMany = 'Member';

//Member
 public $hasOne = 'Post';

其中帖子包含帖子名称

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

$this->Union->findById(1);

在联合控制器中,它显示链接的成员,但不显示帖子的名称

[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 呢?

【问题讨论】:

  • 这样使用:$this->Union->recursive=2;$this->Union->findById(1);

标签: cakephp model model-associations


【解决方案1】:

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

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

$this->Union->recursive = 2;

然后找到你的数据 -

$this->Union->findById(1)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-21
    • 1970-01-01
    • 2020-01-23
    • 1970-01-01
    • 2013-02-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多