From a9f36a352d6fc4b14bfb5af31877337bc0c2c3fa Mon Sep 17 00:00:00 2001 From: Taras Machyshyn Date: Tue, 8 Oct 2019 15:07:55 +0300 Subject: [PATCH] Orm: defined index name for relations --- .../Core/Utils/Database/Orm/Converter.php | 21 +++++++++++++------ .../Espo/Core/Utils/Database/Schema/Utils.php | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) 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;