diff --git a/application/Espo/Core/Utils/Database/Orm/Converter.php b/application/Espo/Core/Utils/Database/Orm/Converter.php index 42fb162279..d3084a4fda 100644 --- a/application/Espo/Core/Utils/Database/Orm/Converter.php +++ b/application/Espo/Core/Utils/Database/Orm/Converter.php @@ -560,14 +560,23 @@ class Converter protected function applyIndexes(&$ormMetadata, $entityType) { - if (!isset($ormMetadata[$entityType]['indexes'])) { - return; + if (isset($ormMetadata[$entityType]['indexes'])) { + foreach ($ormMetadata[$entityType]['indexes'] as $indexName => &$indexData) { + if (!isset($indexData['key'])) { + $indexType = SchemaUtils::getIndexTypeByIndexDefs($indexData); + $indexData['key'] = SchemaUtils::generateIndexName($indexName, $indexType); + } + } } - foreach ($ormMetadata[$entityType]['indexes'] as $indexName => &$indexData) { - if (!isset($indexData['key'])) { - $indexType = SchemaUtils::getIndexTypeByIndexDefs($indexData); - $indexData['key'] = SchemaUtils::generateIndexName($indexName, $indexType); + if (isset($ormMetadata[$entityType]['relations'])) { + foreach ($ormMetadata[$entityType]['relations'] as $relationName => &$relationData) { + if (isset($relationData['indexes'])) { + foreach ($relationData['indexes'] as $indexName => &$indexData) { + $indexType = SchemaUtils::getIndexTypeByIndexDefs($indexData); + $indexData['key'] = SchemaUtils::generateIndexName($indexName, $indexType); + } + } } } } diff --git a/application/Espo/Core/Utils/Database/Schema/Utils.php b/application/Espo/Core/Utils/Database/Schema/Utils.php index 6f92e1e0c8..dfb86d12a6 100644 --- a/application/Espo/Core/Utils/Database/Schema/Utils.php +++ b/application/Espo/Core/Utils/Database/Schema/Utils.php @@ -69,7 +69,7 @@ class Utils if (isset($entityParams['indexes']) && is_array($entityParams['indexes'])) { foreach ($entityParams['indexes'] as $indexName => $indexParams) { $indexType = static::getIndexTypeByIndexDefs($indexParams); - $tableIndexName = static::generateIndexName($indexName, $indexType); + $tableIndexName = isset($indexParams['key']) ? $indexParams['key'] : static::generateIndexName($indexName, $indexType); if (isset($indexParams['flags']) && is_array($indexParams['flags'])) { $skipIndex = false;