DQL query with joining table and two join

前端 未结 1 738
你的背包
你的背包 2020-12-21 00:21

I have 2 entity:

/**
 * @ORM\\Entity
 * @ORM\\Table(name=\"users\")
 */
class User
{
    /**
     * @ORM\\ManyToMany(targetEntity=\"Myapp\\UserBundle\\Entity         


        
相关标签:
1条回答
  • 2020-12-21 00:49

    It's a ManyToMany relation, don't event try to join on the relation table, only the related entity... Then, you were right with the RIGHT JOIN ... for a SQL query, but Doctrine automatically defines the jointure type from the FROM clause.

    In DQL, only defined relations are managed by jointures, so you don't need USE or ON clauses...

    What about this one ?

    SELECT g.name, g.id, count( u.id )
    FROM groups g
    JOIN users u
    GROUP BY g.id
    
    0 讨论(0)
提交回复
热议问题