From 4c51403daa5c92b96bf05e80dc16a03e53944535 Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 11 Jan 2023 14:05:45 +0100 Subject: [PATCH] some bugfixes --- .../Controller/DatabaseEntity.class.php | 8 ++++++++ .../Controller/DatabaseEntityHandler.php | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/Core/Objects/DatabaseEntity/Controller/DatabaseEntity.class.php b/Core/Objects/DatabaseEntity/Controller/DatabaseEntity.class.php index ce3fc93..1b2f5e6 100644 --- a/Core/Objects/DatabaseEntity/Controller/DatabaseEntity.class.php +++ b/Core/Objects/DatabaseEntity/Controller/DatabaseEntity.class.php @@ -94,6 +94,14 @@ abstract class DatabaseEntity implements ArrayAccess, JsonSerializable { } else if ($value instanceof DatabaseEntity) { $subPropertyNames = $propertyNames[$propertyName] ?? null; $value = $value->jsonSerialize($subPropertyNames); + } else if (is_array($value)) { + $subPropertyNames = $propertyNames[$propertyName] ?? null; + $value = array_map(function ($item) use ($subPropertyNames) { + if ($item instanceof DatabaseEntity) { + $item = $item->jsonSerialize($subPropertyNames); + } + return $item; + }, $value); } $jsonArray[$property->getName()] = $value; diff --git a/Core/Objects/DatabaseEntity/Controller/DatabaseEntityHandler.php b/Core/Objects/DatabaseEntity/Controller/DatabaseEntityHandler.php index 8c3b3e0..859b16f 100644 --- a/Core/Objects/DatabaseEntity/Controller/DatabaseEntityHandler.php +++ b/Core/Objects/DatabaseEntity/Controller/DatabaseEntityHandler.php @@ -546,6 +546,10 @@ class DatabaseEntityHandler implements Persistable { ->addSelectValue(new Column($thisIdColumn)) ->where(new CondIn(new Column($thisIdColumn), $entityIds)); + if ($recursive) { + $relEntityQuery->fetchEntities(true); + } + $rows = $relEntityQuery->executeSQL(); if (!is_array($rows)) { $this->logger->error("Error fetching n:m relations from table: '$nmTable': " . $this->sql->getLastError()); @@ -574,6 +578,11 @@ class DatabaseEntityHandler implements Persistable { $relEntityQuery = DatabaseEntityQuery::fetchAll($otherHandler) ->where(new CondIn(new Column($thisIdColumn), $entityIds)); + + if ($recursive) { + $relEntityQuery->fetchEntities(true); + } + $rows = $relEntityQuery->executeSQL(); if (!is_array($rows)) { $this->logger->error("Error fetching n:m relations from table: '$nmTable': " . $this->sql->getLastError()); @@ -591,6 +600,16 @@ class DatabaseEntityHandler implements Persistable { $targetArray[$row[$relIdColumn]] = $relEntity; $property->setValue($thisEntity, $targetArray); } + } else { + $this->logger->error("fetchNMRelations for type '" . get_class($nmRelation) . "' is not implemented"); + continue; + } + + if ($recursive) { + foreach ($entities as $entity) { + $relEntities = $property->getValue($entity); + $otherHandler->fetchNMRelations($relEntities); + } } } }