Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
连接表时出现PHP扫描错误_Php_Orm_Phalcon_Phalcon Orm - Fatal编程技术网

连接表时出现PHP扫描错误

连接表时出现PHP扫描错误,php,orm,phalcon,phalcon-orm,Php,Orm,Phalcon,Phalcon Orm,我正在尝试使用Phalcon\Mvc\Model对象的query()方法连接服务中的两个表。这是我的密码: $result = $this->templateModel->query() ->columns('\Render\Model\Templates.* ') ->leftJoin('\Render\Model\Branches.*', '\Render\

我正在尝试使用Phalcon\Mvc\Model对象的query()方法连接服务中的两个表。这是我的密码:

$result = $this->templateModel->query()
                            ->columns('\Render\Model\Templates.* ')
                            ->leftJoin('\Render\Model\Branches.*', '\Render\Model\Templates.branchId = b.Branches.id', 'b')
                            ->where("branchId = :branchId:")
                            ->bind(['branchId' => $this->branchData['id']])
                            ->execute()
                            ->toArray();
但是,在加载页面时,出现以下错误:

 Phalcon\Mvc\Model\Exception: Scanning error before '\Render\Model\Br...' when parsing: SELECT \Render\Model\Templates.* FROM [Render\Model\Templates] LEFT JOIN [\Render\Model\Branches.*] AS [b] ON \Render\Model\Templates.branchId = b.Branches.id WHERE branchId = :branchId: (187) in /home/vis/projects/stm/app/Service/BranchService.php on line 61
我使用的语法来自(当然,这不是最新的帖子,但我仍然在使用Phalcon 2.0.13)

研究这个问题主要返回查询(,)中禁止使用的半列的结果,但在我的例子中这不是问题所在


注释连接行后,查询工作正常,因此问题一定出在它身上。欢迎提供任何帮助。

它应该是
\Render\Model\branchs
,您还应该使用模型关系别名,以便执行以下操作:

$modelsManager->registerNamespaceAlias('M', 'Render\Model');
然后只需使用
M:branchs

SELECT \Render\Model\Templates.* 
FROM [Render\Model\Templates] 
LEFT JOIN [\Render\Model\Branches.*] AS [b] ON \Render\Model\Templates.branchId = b.Branches.id 
WHERE branchId = :branchId:
我假设您对SQL有点了解。即使是PhQL,您也可能会看到部分
左连接[\Render\Model\branchs.*]
,这看起来很可疑。在此声明中不可能将表连接到列。连接总是发生在两个表之间

一个简单的解决方案:

// -------------------------------v (removed ".*")
->leftJoin('\Render\Model\Branches', '\Render\Model\Templates.branchId = b.Branches.id', 'b')

假设您已正确声明
\Render\Model\branchs
Model.

'\Render\Model\branchs.*'
更改为
'\Render\Model\branchs'
。您需要定义要联接的表,而不是要从联接表中选择的列。谢谢,这样做了。我是认真的最近心不在焉……或者只是使用
branchs::class
而不是键入所有名称空间内容