From 7b8d28d715e8541e075b1ac0da01db9b7ef82359 Mon Sep 17 00:00:00 2001 From: Andrey Tkachenko Date: Wed, 26 Oct 2022 10:54:48 +0200 Subject: [PATCH 1/5] Include real table names in the table map loader --- .../Generator/Builder/Om/TableMapLoaderScriptBuilder.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Propel/Generator/Builder/Om/TableMapLoaderScriptBuilder.php b/src/Propel/Generator/Builder/Om/TableMapLoaderScriptBuilder.php index 365224ab4b..5d8ba4dcf6 100644 --- a/src/Propel/Generator/Builder/Om/TableMapLoaderScriptBuilder.php +++ b/src/Propel/Generator/Builder/Om/TableMapLoaderScriptBuilder.php @@ -63,12 +63,14 @@ protected function buildVars(array $schemas): array foreach ($schemas as $schema) { foreach ($schema->getDatabases(false) as $database) { $databaseName = $database->getName(); - $tableMapNames = array_map([$this, 'getFullyQualifiedTableMapClassName'], $database->getTables()); + $tableMapPhpNames = array_map([$this, 'getFullyQualifiedTableMapClassName'], $database->getTables()); + $tableNames = array_map([$this, 'getTableName'], $database->getTables()); + $tableMapNames = array_combine($tableNames, $tableMapPhpNames); if (array_key_exists($databaseName, $databaseNameToTableMapNames)) { $existing = $databaseNameToTableMapNames[$databaseName]; $tableMapNames = array_merge($existing, $tableMapNames); } - sort($tableMapNames); + ksort($tableMapNames); $databaseNameToTableMapNames[$databaseName] = $tableMapNames; } } From fcc5583bf0cb38eec899391be39c340899555959 Mon Sep 17 00:00:00 2001 From: Andrey Tkachenko Date: Wed, 26 Oct 2022 11:02:08 +0200 Subject: [PATCH 2/5] do not init table classes, only provide a mapping --- src/Propel/Runtime/Map/DatabaseMap.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Propel/Runtime/Map/DatabaseMap.php b/src/Propel/Runtime/Map/DatabaseMap.php index 1d7cad8bf7..2de07c61ab 100644 --- a/src/Propel/Runtime/Map/DatabaseMap.php +++ b/src/Propel/Runtime/Map/DatabaseMap.php @@ -144,16 +144,13 @@ public function addTableFromMapClass(string $tableMapClass): TableMap * {@link DatabaseMap::getTables()} * * @param class-string<\Propel\Runtime\Map\TableMap> $tableMapClass The name of the table map to add + * @param string $tableName The name of the table map to add * * @return void */ - public function registerTableMapClass(string $tableMapClass): void + public function registerTableMapClass(string $tableMapClass, string $tableName): void { - $tableName = $tableMapClass::TABLE_NAME; $this->tables[$tableName] = $tableMapClass; - - $tablePhpName = $tableMapClass::TABLE_PHP_NAME; - $this->addTableByPhpName($tablePhpName, $tableMapClass); } /** @@ -166,7 +163,7 @@ public function registerTableMapClass(string $tableMapClass): void */ public function registerTableMapClasses(array $tableMapClasses): void { - array_map([$this, 'registerTableMapClass'], $tableMapClasses); + array_map([$this, 'registerTableMapClass'], array_values($tableMapClasses), array_keys($tableMapClasses)); } /** From 72b9944e54f8b292c207a96fd4963a029c0fce34 Mon Sep 17 00:00:00 2001 From: Andrey Tkachenko Date: Wed, 26 Oct 2022 11:03:18 +0200 Subject: [PATCH 3/5] fixed doc-block --- src/Propel/Runtime/Map/DatabaseMap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Propel/Runtime/Map/DatabaseMap.php b/src/Propel/Runtime/Map/DatabaseMap.php index 2de07c61ab..c4309ad697 100644 --- a/src/Propel/Runtime/Map/DatabaseMap.php +++ b/src/Propel/Runtime/Map/DatabaseMap.php @@ -144,7 +144,7 @@ public function addTableFromMapClass(string $tableMapClass): TableMap * {@link DatabaseMap::getTables()} * * @param class-string<\Propel\Runtime\Map\TableMap> $tableMapClass The name of the table map to add - * @param string $tableName The name of the table map to add + * @param string $tableName The qualified table name * * @return void */ From 728c9d460ad598b0340113bf51e9c437824014b0 Mon Sep 17 00:00:00 2001 From: Andrey Tkachenko Date: Wed, 26 Oct 2022 11:10:02 +0200 Subject: [PATCH 4/5] added missing function --- .../Builder/Om/TableMapLoaderScriptBuilder.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Propel/Generator/Builder/Om/TableMapLoaderScriptBuilder.php b/src/Propel/Generator/Builder/Om/TableMapLoaderScriptBuilder.php index 5d8ba4dcf6..cea5454fb7 100644 --- a/src/Propel/Generator/Builder/Om/TableMapLoaderScriptBuilder.php +++ b/src/Propel/Generator/Builder/Om/TableMapLoaderScriptBuilder.php @@ -92,7 +92,17 @@ protected function getFullyQualifiedTableMapClassName(Table $table): string return $builder->getFullyQualifiedClassName(); } - + + /** + * @param \Propel\Generator\Model\Table $table + * + * @return string + */ + protected function getTableName(Table $table): string + { + return $table->getCommonName(); + } + /** * @param array $vars * From deb8f6e4c18576cdd9039cca9dc46f51cd9a8068 Mon Sep 17 00:00:00 2001 From: Andrey Tkachenko Date: Wed, 26 Oct 2022 11:14:59 +0200 Subject: [PATCH 5/5] keep BC for registerTableMapClass --- src/Propel/Runtime/Map/DatabaseMap.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Propel/Runtime/Map/DatabaseMap.php b/src/Propel/Runtime/Map/DatabaseMap.php index c4309ad697..a45856a3bf 100644 --- a/src/Propel/Runtime/Map/DatabaseMap.php +++ b/src/Propel/Runtime/Map/DatabaseMap.php @@ -144,12 +144,16 @@ public function addTableFromMapClass(string $tableMapClass): TableMap * {@link DatabaseMap::getTables()} * * @param class-string<\Propel\Runtime\Map\TableMap> $tableMapClass The name of the table map to add - * @param string $tableName The qualified table name + * @param string|null $tableName The name of the table map to add * * @return void */ - public function registerTableMapClass(string $tableMapClass, string $tableName): void + public function registerTableMapClass(string $tableMapClass, string $tableName=null): void { + if (!$tableName) { + $tableName = $tableMapClass::TABLE_NAME; + } + $this->tables[$tableName] = $tableMapClass; }