Skip to content

Commit 8a536fe

Browse files
authored
Merge pull request #676 from utopia-php/fix-nested-select
Fix nested selections getting empty array when all are removed
2 parents d59a207 + 45a1370 commit 8a536fe

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/Database/Database.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7076,7 +7076,12 @@ private function processRelationshipQueries(
70767076
// 'foo.bar.baz' becomes 'bar.baz'
70777077

70787078
$nestingPath = \implode('.', $nesting);
7079-
$nestedSelections[$selectedKey][] = Query::select([$nestingPath]);
7079+
// If nestingPath is empty, it means we want all fields (*) for this relationship
7080+
if (empty($nestingPath)) {
7081+
$nestedSelections[$selectedKey][] = Query::select(['*']);
7082+
} else {
7083+
$nestedSelections[$selectedKey][] = Query::select([$nestingPath]);
7084+
}
70807085

70817086
$type = $relationship->getAttribute('options')['relationType'];
70827087
$side = $relationship->getAttribute('options')['side'];
@@ -7105,7 +7110,13 @@ private function processRelationshipQueries(
71057110
}
71067111
}
71077112

7108-
$query->setValues(\array_values($values));
7113+
$finalValues = \array_values($values);
7114+
if ($query->getMethod() === Query::TYPE_SELECT) {
7115+
if (empty($finalValues)) {
7116+
$finalValues = ['*'];
7117+
}
7118+
}
7119+
$query->setValues($finalValues);
71097120
}
71107121

71117122
return $nestedSelections;
@@ -7138,7 +7149,7 @@ protected function encodeSpatialData(mixed $value, string $type): string
71387149
case self::VAR_POLYGON:
71397150
// Check if this is a single ring (flat array of points) or multiple rings
71407151
$isSingleRing = count($value) > 0 && is_array($value[0]) &&
7141-
count($value[0]) === 2 && is_numeric($value[0][0]) && is_numeric($value[0][1]);
7152+
count($value[0]) === 2 && is_numeric($value[0][0]) && is_numeric($value[0][1]);
71427153

71437154
if ($isSingleRing) {
71447155
// Convert single ring format [[x1,y1], [x2,y2], ...] to multi-ring format

0 commit comments

Comments
 (0)