[PR #8919] feat(ScalarColumnHydrator): added ScalarColumnHydrator to get flat array results from query for single column #11256

Open
opened 2026-01-22 16:10:11 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/8919

State: closed
Merged: Yes


Description:

  • feat(AbstractQuery): added getFlatArrayResultByKey method to Abstract Query to get flat array results from query

How it helps ?

  • Imagine if We just want list of ids from database then we need to implement something like this in repository
$transform = function($item) {
    return $item['id'];
};

$result = array_map($transform, $em->createQuery("SELECT a.id FROM Auction a")->getArrayResult());

With getFlatArrayResultByKey

$em->createQuery("SELECT a.id FROM Auction a")->getFlatArrayResultByKey('id');

and if we don't pass any key then it works same as getArrayResult

**Original Pull Request:** https://github.com/doctrine/orm/pull/8919 **State:** closed **Merged:** Yes --- Description: - feat(AbstractQuery): added getFlatArrayResultByKey method to Abstract Query to get flat array results from query ### How it helps ? - Imagine if We just want list of ids from database then we need to implement something like this in repository ```php $transform = function($item) { return $item['id']; }; $result = array_map($transform, $em->createQuery("SELECT a.id FROM Auction a")->getArrayResult()); ``` With `getFlatArrayResultByKey` ```php $em->createQuery("SELECT a.id FROM Auction a")->getFlatArrayResultByKey('id'); ``` and if we don't pass any key then it works same as `getArrayResult`
admin added the pull-request label 2026-01-22 16:10:11 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#11256