Support join tables in Doctrine Query Language #10143
Replies: 3 comments 1 reply
-
How do you map join tables if you don't have a class for them? |
Beta Was this translation helpful? Give feedback.
-
In my specific case, there is no mapping to any class, because the join table is generated from the association. |
Beta Was this translation helpful? Give feedback.
-
DQL and as a consequence the ORM's query builder do not operate on database tables but on your entity model. This is a different layer of abstraction where the concept of a join table does not exist. The join table is merely an implementation of a many-to-many association. If you want to query your join table using DQL, you need to query the owning entity of the association instead and navigate the entity model from there. If that does not feel right in your case and the entity model is too abstract for what you're attempting to achieve, you can instead run your query against the DBAL connection. Here, you have full control over the SQL that is run on your database server and of course you can query your join table directly. |
Beta Was this translation helpful? Give feedback.
-
Feature Request
Summary
Why is it not possible to specify a table name in the ->createQueryBuilder, but rather a class? Join tables do not have their own class and if you want to make subqueries with DQL, for example, you have to rely on ->prepare. It would be cool to be able to use table names here as well.
Beta Was this translation helpful? Give feedback.
All reactions