How do you query? #5859

Closed
opened 2026-01-22 15:20:20 +01:00 by admin · 1 comment
Owner

Originally created by @manishbathla on GitHub (Jan 27, 2018).

Originally assigned to: @Ocramius on GitHub.

have never used doctrine or any other DAL for that matter but I need to switch. I need to know whether I can query something like this in doctrine

SELECT *
FROM category c
LEFT JOIN category_description cd ON (c.category_id = cd.category_id)
WHERE c.parent_id = '0' AND cd.language_id = '1' ORDER BY c.sort_order

?

Originally created by @manishbathla on GitHub (Jan 27, 2018). Originally assigned to: @Ocramius on GitHub. have never used doctrine or any other DAL for that matter but I need to switch. I need to know whether I can query something like this in doctrine ``` SELECT * FROM category c LEFT JOIN category_description cd ON (c.category_id = cd.category_id) WHERE c.parent_id = '0' AND cd.language_id = '1' ORDER BY c.sort_order ``` ?
admin added the QuestionDQL labels 2026-01-22 15:20:20 +01:00
admin closed this issue 2026-01-22 15:20:20 +01:00
Author
Owner

@Ocramius commented on GitHub (Jan 27, 2018):

Please refer to http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html for documentation of how the doctrine query language works.

What you wrote there is SQL, which can be run on Doctrine DBAL, not in Doctrine ORM.

In Doctrine ORM, the query above would be translated (in DQL) to:

SELECT
    c,
    d
FROM
    My\Namespace\Category c
LEFT JOIN
    c.description d
WHERE
    c.parentId = 0
ORDER BY
    c.sortOrder ASC

If you wanted to select all records where Description#languageId is 1, you'd do that after selecting your Category instances with the query above. See also https://groups.google.com/d/msg/doctrine-user/_1_Nh89--2A/D5CwzSwqDgAJ about why filtering of the association is not really possible without breaking the in-memory data structure.

@Ocramius commented on GitHub (Jan 27, 2018): Please refer to http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html for documentation of how the doctrine query language works. What you wrote there is SQL, which can be run on Doctrine DBAL, not in Doctrine ORM. In Doctrine ORM, the query above would be translated (in DQL) to: ``` SELECT c, d FROM My\Namespace\Category c LEFT JOIN c.description d WHERE c.parentId = 0 ORDER BY c.sortOrder ASC ``` If you wanted to select all records where `Description#languageId` is `1`, you'd do that after selecting your `Category` instances with the query above. See also https://groups.google.com/d/msg/doctrine-user/_1_Nh89--2A/D5CwzSwqDgAJ about why filtering of the association is not really possible without breaking the in-memory data structure.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5859