I'm trying to join two tables in a service, using the query() method of a Phalcon\Mvc\Model object. Here's my code:
$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();
However, when loading the page, I get the following error:
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
The syntax I used comes from this Stackoverflow entry (granted, it's not the newest post, but I'm still using Phalcon 2.0.13.
Researching the problem mostly returns results about forbidden semicolumns in the query (example1, example2), but that's not the issue in my case.
With the join line commented, the query works fine, so the problem must lie in it. Any help is appreaciated.
'\Render\Model\Branches.*'to'\Render\Model\Branches'. You need to define the table you want to join with. Not the columns you want to select from the joining table - Timothy