gpt4 book ai didi

php - PhalconPHP 加入模型 Echo

转载 作者:行者123 更新时间:2023-11-29 22:22:30 24 4
gpt4 key购买 nike

好的,我有两张 table 。一个称为 Properties,另一个称为 PrInfo

Properties 是基表,PrInfo 是另一个包含额外信息的表。

我想将它们连接在一起,以便我可以在网站上显示信息。

    $query = Properties::query()
->leftJoin('PrInfo','pr.pr_id = Properties.id','pr')
->execute();

在我看来,自声明“pr.pr_id = Properties.id”以来,查询的每个索引都应与 PrInfo 表中的一行连接

但是,当我仅键入“print_r($query[1]);”时,我可以在执行的查询中看到确实已包含 pr_info 表,但我不确定它是否与属性表中的行匹配。

我尝试执行 print_r($query[1]['PrInfo'] 但出现错误。

有什么想法吗?

有以下内容

          protected '_hasManyToManySingle' => null
protected '_initialized' =>
array (size=2)
...
protected '_sources' => null
protected '_schemas' => null
protected '_behaviors' => null
protected '_lastInitialized' =>
object(PrInfo)[51]
...
protected '_lastQuery' => null
protected '_reusable' => null
protected '_keepSnapshots' => null
protected '_dynamicUpdate' => null
protected '_namespaceAliases' => null
protected '_modelsMetaData' => null
protected '_errorMessages' => null

最佳答案

您应该在模型中定义适当的关系,如下所示,而不是使用 leftJoin() 手动加入:

class Properties extends Model
{
...

public function initialize()
{
$this->hasMany("id", "PrInfo", "pr_id");
}

}

欲了解更多相关信息,请访问: http://docs.phalconphp.com/en/latest/reference/models.html#relationships-between-models

关于php - PhalconPHP 加入模型 Echo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30576686/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com