some bugfixes

This commit is contained in:
Roman 2023-01-11 14:05:45 +01:00
parent dee9d8c34e
commit 4c51403daa
2 changed files with 27 additions and 0 deletions

@ -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;

@ -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);
}
}
}
}