DQL docs - I'll write clarifications in the docs if someone can elaborate a few things #5609

Closed
opened 2026-01-22 15:12:38 +01:00 by admin · 2 comments
Owner

Originally created by @bitwombat on GitHub (Jul 19, 2017).

Originally assigned to: @Ocramius on GitHub.

Hi Contributors,

I think there are some behaviours/logic in DQL usage that aren't clear in the documentation.

  1. The docs say:

"The select clause of a DQL query specifies what appears in the
query result. "

Is it more that what is selected is hydrated? Because what 'appears' in the result is an array of the entity specified by FROM, yes?

  1. I think there is a difference between
    SELECT u.name, u.username
    vs
    SELECT u
    vs
    SELECT u, u.name

It's unclear from the docs what this difference is. I haven't done enough experimenting yet, but I know if I don't have at least the FROM entity in the SELECT, I get "Cannot select entity through identification variables without choosing at least one root entity alias."

  1. The differences between WHERE, WITH and HAVING are not clear.

I'd like to write the clarifications and submit a PR, but I need a bit of help making sure I understand.

Thanks!
Greg

Originally created by @bitwombat on GitHub (Jul 19, 2017). Originally assigned to: @Ocramius on GitHub. Hi Contributors, I think there are some behaviours/logic in DQL usage that aren't clear in the documentation. 1) The docs say: "The select clause of a DQL query specifies what appears in the query result. " Is it more that what is selected is *hydrated*? Because what 'appears' in the result is an array of the entity specified by FROM, yes? 2) I think there is a difference between `SELECT u.name, u.username` vs `SELECT u` vs `SELECT u, u.name` It's unclear from the docs what this difference is. I haven't done enough experimenting yet, but I know if I don't have at least the FROM entity in the SELECT, I get "Cannot select entity through identification variables without choosing at least one root entity alias." 3) The differences between WHERE, WITH and HAVING are not clear. I'd like to write the clarifications and submit a PR, but I need a bit of help making sure I understand. Thanks! Greg
admin added the DocumentationDuplicate labels 2026-01-22 15:12:38 +01:00
admin closed this issue 2026-01-22 15:12:38 +01:00
Author
Owner

@Ocramius commented on GitHub (Jul 21, 2017):

"The select clause of a DQL query specifies what appears in the
query result. "
Is it more that what is selected is hydrated? Because what 'appears' in the result is an array of the entity specified by FROM, yes?

You are correct - fetch-joins will hydrate INTO the root of the selection. Technically, it is still what is being put in the result, just not in a very intuitive way.

I think there is a difference between
SELECT u.name, u.username
vs
SELECT u
vs
SELECT u, u.name

Yes, the first one will give you an array of scalars per row, the second one an entity per row, the third an array with the entity and the scalar.

if I don't have at least the FROM entity in the SELECT, I get "Cannot select entity through identification variables without choosing at least one root entity alias."

You can select scalars from any entity in the selection, you can select the entity in the FROM, but you cannot select other entities unless you also select the root of the selection (first entity in FROM).

The differences between WHERE, WITH and HAVING are not clear.

  • WHERE is applied to the results of an entire query
  • WITH is applied to a join as an additional condition. For arbitrary joins (SELECT f, b FROM Foo f, Bar b WITH f.id = b.id) the WITH is required, even if it is 1 = 1
  • HAVING is applied to the results of a query after aggregation (GROUP BY)
@Ocramius commented on GitHub (Jul 21, 2017): > "The select clause of a DQL query specifies what appears in the query result. " > Is it more that what is selected is hydrated? Because what 'appears' in the result is an array of the entity specified by FROM, yes? You are correct - fetch-joins will hydrate INTO the root of the selection. Technically, it is still what is being put in the result, just not in a very intuitive way. > I think there is a difference between > `SELECT u.name, u.username` > vs > `SELECT u` > vs > `SELECT u, u.name` Yes, the first one will give you an array of scalars per row, the second one an entity per row, the third an array with the entity and the scalar. > if I don't have at least the FROM entity in the SELECT, I get "Cannot select entity through identification variables without choosing at least one root entity alias." You can select scalars from any entity in the selection, you can select the entity in the `FROM`, but you cannot select other entities unless you also select the root of the selection (first entity in `FROM`). > The differences between WHERE, WITH and HAVING are not clear. * `WHERE` is applied to the results of an entire query * `WITH` is applied to a join as an *additional* condition. For arbitrary joins (`SELECT f, b FROM Foo f, Bar b WITH f.id = b.id`) the `WITH` is required, even if it is `1 = 1` * `HAVING` is applied to the results of a query *after* aggregation (`GROUP BY`)
Author
Owner

@Ocramius commented on GitHub (Aug 18, 2017):

Closing here: moved to #6572

@Ocramius commented on GitHub (Aug 18, 2017): Closing here: moved to #6572
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5609