Skip to content

Instantly share code, notes, and snippets.

@ker0x
Created June 21, 2024 09:58
Show Gist options
  • Save ker0x/34ddc2f2d9fbb90e33ba85a9271701c7 to your computer and use it in GitHub Desktop.
Save ker0x/34ddc2f2d9fbb90e33ba85a9271701c7 to your computer and use it in GitHub Desktop.
Doctrine SELECT with relation
<?php
private function findSelectWithRelation(): array
{
$queryBuilder = $this->createQueryBuilder('invoice')
->select('
invoice.id AS invoiceId,
SUBSTRING_INDEX(
GROUP_CONCAT(history.id ORDER BY history.date DESC SEPARATOR \'#\'),
\'#\',
1
) AS lastHistoryId
'
)
->leftJoin('invoice.histories', 'history')
;
return $queryBuilder->getQuery()->getArrayResult();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment