In this post, DRapp provided an SQL query for solving the problem proposed by Ali. In practice, Ali asked how to write a query capable of returning all the rows from the table Category related to a row in the Post table, in order to do what we can see in all the catalog-based websites (eBay, Amazon, etc.).
This stated, how the SQL query proposed in the DRapp’s solution can be written with Doctrine2?
Please, avoid using QueryBuilder.
PS: I use MySQL.
I believe that it is not possible to write such a query like the one mentioned in the question by using DQL or the QueryBuilder directly. However, one possibility is to use Doctrine2 Native Query, which let the use to execute a raw SQL.
For sake of completeness, here follows the query by DRapp.