Problem in having with 'or' or orHaving #6268

Closed
opened 2026-01-22 15:29:55 +01:00 by admin · 4 comments
Owner

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:

$qb = $this->entityManager->getRepository(Product::class)->createQueryBuilder('p');
		$qb->leftJoin(File::class, 'f', Join::WITH, 'f.itemId = p.id AND f.categoryId = p.idk');
		$qb->distinct(TRUE);
		$qb->select('p.id,p.title, p.deliveryCode, p.code, f.orderBy as orderBy, f.name, f.id as fid, f.extension, p.cenaOld, p.supplierPrice');
		$qb->addGroupBy('p.id');
		$qb->addOrderBy('p.title', 'ASC');
		$qb->having('(min(orderBy) or orderBy is null)');

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

Q A
BC Break no
Version 2.6.3

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

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: ```php $qb = $this->entityManager->getRepository(Product::class)->createQueryBuilder('p'); $qb->leftJoin(File::class, 'f', Join::WITH, 'f.itemId = p.id AND f.categoryId = p.idk'); $qb->distinct(TRUE); $qb->select('p.id,p.title, p.deliveryCode, p.code, f.orderBy as orderBy, f.name, f.id as fid, f.extension, p.cenaOld, p.supplierPrice'); $qb->addGroupBy('p.id'); $qb->addOrderBy('p.title', 'ASC'); $qb->having('(min(orderBy) or orderBy is null)'); ``` 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 | Q | A |------------ | ------ | BC Break | no | Version | 2.6.3 #### 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
admin added the BugInvalid labels 2026-01-22 15:29:55 +01:00
admin closed this issue 2026-01-22 15:29:55 +01:00
Author
Owner

@SenseException commented on GitHub (Jul 15, 2019):

@JohnyRicio Can you please format your code snippet? Formatting code in markdown is possible like this:

``` php

echo 'Hello world';

```
@SenseException commented on GitHub (Jul 15, 2019): @JohnyRicio Can you please format your code snippet? Formatting code in markdown is possible like this: ```` ``` php echo 'Hello world'; ``` ````
Author
Owner

@JohnyRicio commented on GitHub (Jul 15, 2019):

Of course

@JohnyRicio commented on GitHub (Jul 15, 2019): Of course
Author
Owner

@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)');

@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)');`
Author
Owner

@lcobucci commented on GitHub (Sep 16, 2019):

Closing as invalid as per @svbackend's comment.

@lcobucci commented on GitHub (Sep 16, 2019): Closing as invalid as per @svbackend's comment.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6268