2013-02-04 92 views
2

我對propel中的外鍵有疑問。 我有我的項目2點的模式相匹配2個物理數據庫即: 我的地方一(DB一),並與一些一 遠程數據庫的只讀信息(DB二)使用Propel的遠程數據庫的外鍵

的一點是,我需要設置從DB One到DB Two的外鍵,但它不起作用。 這裏是我的架構:

模式1

<database package="dbOne" defaultIdMethod="native" name="dbOne"> 
    <table name="tableOne"> 
    <column name="pk_tableOne" type="INTEGER" primaryKey="true" required="true" autoIncrement="true"/> 
    <column name="column_one" type="DOUBLE" required="true"/> 
    <foreign-key name="fk_column_one" foreignTable="tableTwo" foreignSchema = "dbTwo"> 
     <reference local="column_one" foreign="column_two"/> 
    </foreign-key> 
     </table> 
</database> 

模式2

<database package="dbTwo" defaultIdMethod="native" name="dbTwo"> 
    <table name="tableTwo"> 
    <column name="column_two" type="DOUBLE" primaryKey="true" required="true"/> 
</database> 

我已經OM/diff命令我得到的過程中設置兩種運行時/建造-conf.xml中與兩個數據源,此錯誤:

Execution of target "om-template" failed for the following reason: "tableOne" contains a foreign key to nonexistent table "dbTwo.tableTwo"

我在做什麼錯?

+0

您是否嘗試刪除每個數據庫節點的'package'屬性? – j0k

+0

是的,它返回相同的錯誤 – user2038988

回答

1

不幸的是,我不認爲你將能夠設置外鍵引用不同的數據庫上的表。如果你看一下生成的文件,我們看到這一行:

propel/generator/lib/model/Table.php,線901在current github version

public function setupReferrers($throwErrors = false) 
{ 
    foreach ($this->getForeignKeys() as $foreignKey) { 

    // table referrers 
    $foreignTable = $this->getDatabase()->getTable($foreignKey->getForeignTableName()); 
    if ($foreignTable !== null) { 
     ... 
    } elseif ($throwErrors) { 
     throw new BuildException(sprintf(
     'Table "%s" contains a foreign key to nonexistent table "%s"', 
     $this->getName(), 
     $foreignKey->getForeignTableName() 
    )); 
    } 
    ... 
    } 
    ... 
} 

重點線是在那裏說$foreignTable = $this->getDatabase()...換句話說,它只會工作的引用該表的自己的數據庫。我建議你把你的聲音加到this github issue這似乎是你要求的。

0

您無法加入外國數據庫。但是:如果你的數據庫支持它(你需要一個像PGSQL這樣的數據庫),你可以將表格放置在同一個數據庫中的獨立模式中。這使您可以分開您的表格,但可以應用連接(並設置外鍵)。