Reputation: 395
iam trying to join multiple tables in my bundle using DQL and
Error:
[Syntax Error] line 0, col 610: Error: Expected =, <, <=, <>, >, >=, !=, got 'CarparkFueltext'
Entity:
https://gist.github.com/anonymous/9fc7bfe89bb54427f89c
Code:
https://gist.github.com/anonymous/63680019a3f260733dca
I have also tried with createQueryBuilder() method
Code:
https://gist.github.com/anonymous/92012697fc99fcf02da5
ERROR:
[Syntax Error] line 0, col 423: Error: Expected Literal, got 'JOIN'
However if i remove either of the join statements
JOIN MyBundle:SpareParts\CarparkAgestext CarparkAgestext
OR
JOIN MyBundle:SpareParts\CarFueltext CarFueltext
I am getting the data.
The error seems to be that I cannt join multiple tables and i need to join atleast 5 tables to it. Any Idea how can i acheive it.
Upvotes: 0
Views: 2352
Reputation: 821
Maybe you're trying to JOIN two tables with no relationship defined. If that's the case you can JOIN them using WITH
FROM FooBundle:Entity1 e1 JOIN FooBundle:Entity2 e2 WITH e2.e1_id = e1.id
Upvotes: 0
Reputation: 4210
Join syntax is here.
General example:
...
->select(['e1'])
->from('AcmeDemoBundle:Entity1', 'e1')
->innerJoin('AcmeDemoBundle:Entity2', 'e2', 'WITH', 'e2.e1 = e1')
->innerJoin('AcmeDemoBundle:Entity3', 'e3', 'WITH', 'e3.e2 = e2')
...
Upvotes: 2
Reputation: 1730
You can join multiple tables, but you need to use the right association of MyBundle:SpareParts\Carparktype
.
You should use a query like the following one:
$query = $this->getEntityManager()->createQueryBuilder()
->select($fields)
->from('MyBundle:SpareParts\Carparktype Carparktype')
->innerJoin('Carparktype.agesText CarparkAgestext')
->where('Carparktype.makename =:makename')
->andWhere('CarparkAgestext.id =:agesid')
->setParameter('makename',$makename)
->setParameter('agesid',$param)
->getQuery()
->getResult();
As you see you will build a JOIN statement starting from a single property of SpareParts\Carparktype
, which will be mapped as an association (a foreign key) for SpareParts\CarparkAgestext
.
Upvotes: 0