A
A
art_guzev2020-05-07 22:04:01
symfony
art_guzev, 2020-05-07 22:04:01

How to make multiple Join to same table symfony, querybuilder?

There is a command table:
command_id | team_name

There is a match table:
match_number | home_team_id | id_guest_team
id teams in the "match" table are equal to id teams from the "team" table

In symfony3 using querybuilder I make a selection

$match= $this->getDoctrine()->getEntityManager()
      ->createQueryBuilder()
       ->select ('p.idMatch, pp.name, dp.name')
      ->from('match', 'p')
      ->innerJoin('AppBundle:teams', 'pp', 'with', "p.hometeam = pp.teamId")
      ->innerJoin('AppBundle:teams', 'dp', 'with', "p.awayteam = dp.teamId")
      ->getQuery()
      ->getResult();

But one command is output. How to make it output two commands?

In normal sql I understand how to do it
SELECT
    g.*,
    t1.name AS home_team_name,
    t2.name AS guest_team_name
FROM
    game AS g
    INNER JOIN team AS t1 ON g.home_team_id = t1.id
    INNER JOIN team AS t2 ON g.guest_team_id = t2.id;
ORDER by game_date DESC

here, either write AS in the select somehow, or add alias - I don’t know how to do either one or the other

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2020-05-08
@wyster

Try

->select('p.idMatch')->addSelect('pp.name as home_team_name')->addSelect('dp.name as guest_team_id')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question