0

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.

4
  • Possible duplicate of How can I join multiple tables in symfony2? Commented Oct 10, 2015 at 14:57
  • I tried adding other tables its still the same error Commented Oct 10, 2015 at 15:16
  • can you give the code of your entities (in order to see the mapping), then it will be easy to answer your question Commented Oct 11, 2015 at 0:35
  • I uploaded the code... the entities are unidirectional ManyToOne Relationship Commented Oct 11, 2015 at 9:15

3 Answers 3

2

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')
    ...
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

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

5 Comments

No the two tables have relationship if not how could i get the data with only ONE Join statement..? I dont get data only if I have morethan ONE Join statements
In Doctrine, like MySQL, you can JOIN tables, no matter if they have a relationship or not, using the syntax I provided in my post.
Okay I got it... I am now able to see the data.. I wonder why it didnt work with CreateQueryBuilder and createQuery methods
It seems like the relationship is some how broken... Idk where
I think you should define them in a more standard way. "id" for primary keys, "name_of_entity_id" for foreign keys. you don't need @ORM\JoinColumns({}) with only one JoinColumn inside, so you can remove it. Keep it simple and it'll be less error-prone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.