DQL functions return type is respected by getSingleResult but not getSingleScalarResult. #6595

Open
opened 2026-01-22 15:35:28 +01:00 by admin · 0 comments
Owner

Originally created by @VincentLanglet on GitHub (Dec 24, 2020).

Since https://github.com/doctrine/orm/pull/7941, DQL functions can specify return type.

For instance COUNT is supposed to return an int.

$query = $this->_em->createQuery('SELECT COUNT(product.id) as count FROM product');
$result = $query->getSingleResult(); // ['count' => 6]

But if getSingleScalarResult is used instead of getSingleResult the return type is not used.

$query = $this->_em->createQuery('SELECT COUNT(product.id) as count FROM product');
$result = $query->getSingleScalarResult(); // '6'

It's maybe related to https://github.com/doctrine/orm/issues/8155, but can be a first smaller step

Originally created by @VincentLanglet on GitHub (Dec 24, 2020). Since https://github.com/doctrine/orm/pull/7941, DQL functions can specify return type. For instance `COUNT` is supposed to return an `int`. ``` $query = $this->_em->createQuery('SELECT COUNT(product.id) as count FROM product'); $result = $query->getSingleResult(); // ['count' => 6] ``` But if `getSingleScalarResult` is used instead of `getSingleResult` the return type is not used. ``` $query = $this->_em->createQuery('SELECT COUNT(product.id) as count FROM product'); $result = $query->getSingleScalarResult(); // '6' ``` It's maybe related to https://github.com/doctrine/orm/issues/8155, but can be a first smaller step
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6595