mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Partial query ignores where statement if not in select #5717
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @escopecz on GitHub (Sep 26, 2017).
Originally assigned to: @Ocramius on GitHub.
Following query examples are output of
getDql()method with pasted parameters for easier understanding of the problem.This query does what I'd expect. It returns all company fields:
However this query returns ALL fields, not only company fields:
It took me a while to find out what's going on there. If I specifically list the
objectcolumn in the select clause, the where condition will work again and only company fields will be returned:I couldn't find any documentation on this topic nor any reported issue. Why does it work that way? Isn't it a bug?
@Ocramius commented on GitHub (Sep 26, 2017):
@escopecz can you do a
->getSQL()too?@escopecz commented on GitHub (Sep 26, 2017):
@Ocramius doesn't seem I can:
We're on
"doctrine/orm": "~2.5.4"@Ocramius commented on GitHub (Sep 26, 2017):
@ebernhardson you should do
$queryBuilder->getQuery()->getSql()annd dump that to check if the condition is applied.@escopecz commented on GitHub (Sep 26, 2017):
Thanks for the guidance. Here is the SQL if I specify the id and object in the select clause which is returning the correct results:
This is without the object column specified which is returning all fields of all objects:
@Ocramius commented on GitHub (Sep 26, 2017):
@escopecz what is the resultset like, and what did you expect?
Query looks fine, by the way.
@escopecz commented on GitHub (Sep 26, 2017):
Ok, I think it's not a doctrine bug. The entities will return the default value if the column isn't fetched from the database. So it is returning
companyfields, but object isleadbecause that's the default value.@Ocramius Thanks for helping me realize that!