From a25fe7db02cf3a4ed06958bd870394c593dfb646 Mon Sep 17 00:00:00 2001 From: Prateek Sureka Date: Sat, 14 Nov 2020 14:08:16 +0530 Subject: [PATCH] Added functionality to use foreignSchema attribute of foreign-key tag to create foreign key links to other databases in the same propel project --- src/Propel/Generator/Model/Database.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Propel/Generator/Model/Database.php b/src/Propel/Generator/Model/Database.php index 3dcdc5be2f..fb1e3c62e3 100644 --- a/src/Propel/Generator/Model/Database.php +++ b/src/Propel/Generator/Model/Database.php @@ -484,6 +484,18 @@ public function getTable($name, $caseInsensitive = false) && strpos($name, $this->getPlatform()->getSchemaDelimiter()) === false ) { $name = $this->getSchema() . $this->getPlatform()->getSchemaDelimiter() . $name; + } else if (strpos($name, '.') !== false){ + /* + For pgSql and other dbs which support schemas, getSchema will work exactly as expected. + For other dbs, the attribute can be used to link to databases within the same propel projec + */ + $db = explode(".", $name)[0]; + $name = explode(".", $name)[1]; + + $sc = $this->getParentSchema(); + $db = $sc->getDatabase($db, false); + + return $db->getTable($name); } if (!$this->hasTable($name, $caseInsensitive)) {