Symfony2/Doctrine - Query Join with three different entities

Asked

Viewed 112 times

1

The way below works correctly:

$qb->select('partial t.{id,nsu,status,message}, partial u.{id,shortName,email} as user')
   ->from('GatewayBundle:Transaction', 't')
   ->join('GatewayBundle:User', 'u')
   ->where('u.id = t.user');

When I add another join, results in a error syntax:

ERROR - [Syntax Error] line 0, col 461: Error:Expected Literal, got 'JOIN' 500 Internal Server Error - Queryexception

$qb->select('partial t.{id,nsu,status,message}, partial u.{id,shortName,email} as user, partial p.{id} as partner')
   ->from('GatewayBundle:Transaction', 't')
   ->join('GatewayBundle:User', 'u')
   ->join('GatewayBundle:Partner', 'p')
   ->where('u.id = t.user')
   ->andWhere('p.id = t.partner');

What is the correct syntax for this type of query?

1 answer

1

Worked this way:

$qb
    ->select('
        t.id, t.nsu, t.status, t.message, 
        u.id as u_id, u.shortName as u_shortName , u.email as u_email, 
        p.id as p_id, p.name as p_name')
    ->from('PaylevenGatewayBundle:Transaction', 't')
    ->join('t.user', 'u')
    ->join('t.partner', 'p');
  • If it worked, don’t forget to validate your own answer :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.