mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Problem in having with 'or' or orHaving #6268
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 @JohnyRicio on GitHub (Jul 11, 2019).
Originally assigned to: @lcobucci on GitHub.
Bug Report
When I trayd to use orHaving in query builder, i will see error: line 0, col 298: Error: Expected =, <, <=, <>, >, >=, !=, got 'or'
Input query:
You can change $qb->having('(min(orderBy) or orderBy is null)'); to:
$qb->having('min(orderBy)');
$qb->having('orderBy is null');
The DQL is correct:
SELECT DISTINCT p.id,p.title, p.deliveryCode, p.code, f.orderBy as orderBy, f.name, f.id as fid,
f.extension, p.cenaOld, p.supplierPrice
FROM Ant\Eshop\Product p
LEFT JOIN Ant\Media\File f WITH f.itemId = p.id AND f.categoryId = p.idk
WHERE p.id in (:productIds)
GROUP BY p.id
HAVING (min(orderBy) or orderBy is null)
ORDER BY p.title ASC
but parser return:
line 0, col 298: Error: Expected =, <, <=, <>, >, >=, !=, got 'or'
doctrine\orm\lib\Doctrine\ORM\Query\Parser.php:456
Summary
Query builder parser can't parse the query. But I think, that the query is correct.
Current behavior
Return error: line 0, col 298: Error: Expected =, <, <=, <>, >, >=, !=, got 'or'
How to reproduce
Use query builder to prepare query with having operand, where you will try to use 'or' in having clausule
Expected behavior
Command will run
@SenseException commented on GitHub (Jul 15, 2019):
@JohnyRicio Can you please format your code snippet? Formatting code in markdown is possible like this:
@JohnyRicio commented on GitHub (Jul 15, 2019):
Of course
@svbackend commented on GitHub (Aug 30, 2019):
Its not doctrine bug, problem in line:
$qb->having('(min(orderBy) or orderBy is null)');You need to specify condition for min(orderBy) also, not only for orderBy.
Example of fixed query (but im not sure that its what you want):
$qb->having('(min(orderBy) IS NULL or orderBy is null)');@lcobucci commented on GitHub (Sep 16, 2019):
Closing as invalid as per @svbackend's comment.