in Education by
I have 2 entity: /** * @ORM\Entity * @ORM\Table(name="users") */ class User { /** * @ORM\ManyToMany(targetEntity="Myapp\UserBundle\Entity\Group") * @ORM\JoinTable(name="user_groups", * joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}, * inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")} * ) */ protected $groups; ... } and /** * @ORM\Entity(repositoryClass="Myapp\UserBundle\Repository\GroupRepository") * @ORM\Table(name="groups") */ class Group ... I cant find a way to create a DQL query which results SQL like this: SELECT g.name, g.id, count( u.id ) FROM users u LEFT JOIN user_groups ug ON u.id = ug.user_id RIGHT JOIN groups g ON g.id = ug.group_id GROUP BY g.id I tried and failed whith: $this->getEntityManager() ->createQuery(' SELECT g.id, g.name, count(u.id) as usercount FROM MyappUserBundle:User u JOIN u.groups g GROUP BY g.id' ); since the result not contains the groups that has no user. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
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

Related questions

0 votes
    The tables are: 1) Producers: id, name 2) Products: id, name, price, category_id, producer_id 3) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 11, 2022 in Education by JackTerrance
0 votes
    Joining two lists can be achieved either using the _________ function. (a) Concat (b) Join (c) Reduce (d) ... and Out of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    What is the process of joining two input columns in the tMap configuration window? Dragging a column from the main ... two distinct input tables dragging them to the output table...
asked Mar 24, 2021 in Technology by JackTerrance
0 votes
    I have two tables containing Tasks and Notes, and want to retrieve a list of tasks with the number ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 12, 2022 in Education by JackTerrance
0 votes
    Which product is returned in a join query have no join condition: (a) Equijoins (b) Cartesian (c) ... Answers, Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    Make Twenty (20) SQL questions including create table, insert, update, delete, join, string operation, aggregate ... books or webs Select the correct answer from above options...
asked Dec 9, 2021 in Education by JackTerrance
0 votes
    Make Twenty (20) SQL questions including create table, insert, update, delete, join, string operation, aggregate ... books or webs Select the correct answer from above options...
asked Dec 3, 2021 in Education by JackTerrance
0 votes
    Which join refers to join records from the right table that have no matching key in the left table are ... , Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    Which join refers to join records from the write table that have no matching key in the left table ... Join Operations in chapter Query Processing Techniques of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    I know we are all using a bunch of ORMs for SQL, but I wanted to give a try to native drivers. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I have a n...n structure for two tables, makes and models. So far no problem. In a third table ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    1. Name the term which is used to join two separate arrays into a single array. 2. How are the following ... answer fast I want please Select the correct answer from above options...
asked Dec 13, 2021 in Education by JackTerrance
0 votes
    1. Name the term which is used to join two separate arrays into a single array. 2.How are the following ... ii) primitive type data Select the correct answer from above options...
asked Dec 13, 2021 in Education by JackTerrance
0 votes
    malo 4. Name the term which is used to join two separate arrays into a single array. 5. How are the following passed to the functions? Select the correct answer from above options...
asked Dec 13, 2021 in Education by JackTerrance
0 votes
    I need to perform a query to limit the rows displayed in a table. I chose QTableView/QSqlTableModel for ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
...