Skip to content

Commit 45a1370

Browse files
committed
Fix nested selections getting empty array when all are removed
1 parent 99beaf1 commit 45a1370

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
@@ -7024,7 +7024,12 @@ private function processRelationshipQueries(
70247024
// 'foo.bar.baz' becomes 'bar.baz'
70257025

70267026
$nestingPath = \implode('.', $nesting);
7027-
$nestedSelections[$selectedKey][] = Query::select([$nestingPath]);
7027+
// If nestingPath is empty, it means we want all fields (*) for this relationship
7028+
if (empty($nestingPath)) {
7029+
$nestedSelections[$selectedKey][] = Query::select(['*']);
7030+
} else {
7031+
$nestedSelections[$selectedKey][] = Query::select([$nestingPath]);
7032+
}
70287033

70297034
$type = $relationship->getAttribute('options')['relationType'];
70307035
$side = $relationship->getAttribute('options')['side'];
@@ -7053,7 +7058,13 @@ private function processRelationshipQueries(
70537058
}
70547059
}
70557060

7056-
$query->setValues(\array_values($values));
7061+
$finalValues = \array_values($values);
7062+
if ($query->getMethod() === Query::TYPE_SELECT) {
7063+
if (empty($finalValues)) {
7064+
$finalValues = ['*'];
7065+
}
7066+
}
7067+
$query->setValues($finalValues);
70577068
}
70587069

70597070
return $nestedSelections;
@@ -7086,7 +7097,7 @@ protected function encodeSpatialData(mixed $value, string $type): string
70867097
case self::VAR_POLYGON:
70877098
// Check if this is a single ring (flat array of points) or multiple rings
70887099
$isSingleRing = count($value) > 0 && is_array($value[0]) &&
7089-
count($value[0]) === 2 && is_numeric($value[0][0]) && is_numeric($value[0][1]);
7100+
count($value[0]) === 2 && is_numeric($value[0][0]) && is_numeric($value[0][1]);
70907101

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

0 commit comments

Comments
 (0)