From 43e72efb1ec1a48e7cd110e0947174c7cc62d7db Mon Sep 17 00:00:00 2001 From: Viktor Masicek Date: Mon, 5 Aug 2024 17:13:22 +0200 Subject: [PATCH] Enable own callable post fetch --- src/QueryObject.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/QueryObject.php b/src/QueryObject.php index f0e3ddb..f11b144 100644 --- a/src/QueryObject.php +++ b/src/QueryObject.php @@ -679,6 +679,11 @@ public static function doPostFetch(EntityManagerInterface $em, array $rootEntiti $childrenFieldNames = []; // fieldName => childrenFieldNames foreach ($fieldNames as $fieldName) { + if (is_callable($fieldName)) { + $fieldName($em, $rootEntities); + continue; + } + if (!Strings::contains($fieldName, '.')) { // fetch jen pro toto pole $currentFieldNames[] = $fieldName; @@ -916,10 +921,10 @@ final public function postFetch(Iterator $iterator): void /** * Přidá pole do seznamu pro postFetch. - * @param string $fieldName Může být název pole (např. "contact") nebo cesta (např. "commission.contract.client"). + * @param string|callable $fieldName Může být název pole (např. "contact") nebo cesta (např. "commission.contract.client"). * @return $this */ - final public function addPostFetch(string $fieldName): static + final public function addPostFetch(string|callable $fieldName): static { $this->postFetch[] = $fieldName; return $this;