Skip to content

Commit df7902c

Browse files
updated index lookup
1 parent f2f5ee3 commit df7902c

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

src/Database/Database.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,19 +2244,29 @@ public function updateAttribute(string $collection, string $id, ?string $type =
22442244
throw new LimitException('Row width limit reached. Cannot update attribute.');
22452245
}
22462246

2247-
// checking required of attributes in case of spatial types
2248-
if (in_array($type, Database::SPATIAL_TYPES) && !$this->adapter->getSupportForSpatialIndexNull()) {
2247+
if (in_array($type, self::SPATIAL_TYPES, true) && !$this->adapter->getSupportForSpatialIndexNull()) {
22492248
$attributeMap = [];
2250-
foreach ($attributes as $attribute) {
2251-
$key = \strtolower($attribute->getAttribute('key', $attribute->getAttribute('$id')));
2252-
$attributeMap[$key] = $attribute;
2249+
foreach ($attributes as $attrDoc) {
2250+
$key = \strtolower($attrDoc->getAttribute('key', $attrDoc->getAttribute('$id')));
2251+
$attributeMap[$key] = $attrDoc;
22532252
}
2253+
22542254
$indexes = $collectionDoc->getAttribute('indexes', []);
22552255
foreach ($indexes as $index) {
2256-
$attributes = $index->getAttribute('attributes', []);
2257-
foreach ($attributes as $attributeName) {
2258-
$attribute = $attributeMap[\strtolower($attributeName)];
2259-
if (!$required) {
2256+
if ($index->getAttribute('type') !== self::INDEX_SPATIAL) {
2257+
continue;
2258+
}
2259+
$indexAttributes = $index->getAttribute('attributes', []);
2260+
foreach ($indexAttributes as $attributeName) {
2261+
$lookup = \strtolower($attributeName);
2262+
if (!isset($attributeMap[$lookup])) {
2263+
continue;
2264+
}
2265+
$attrDoc = $attributeMap[$lookup];
2266+
$attrType = $attrDoc->getAttribute('type');
2267+
$attrRequired = (bool)$attrDoc->getAttribute('required', false);
2268+
2269+
if (in_array($attrType, self::SPATIAL_TYPES, true) && !$attrRequired) {
22602270
throw new IndexException('Spatial indexes do not allow null values. Mark the attribute "' . $attributeName . '" as required or create the index on a column with no null values.');
22612271
}
22622272
}

0 commit comments

Comments
 (0)