Created
June 21, 2024 09:58
-
-
Save ker0x/34ddc2f2d9fbb90e33ba85a9271701c7 to your computer and use it in GitHub Desktop.
Doctrine SELECT with relation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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