2011-07-28 21 views
0

我正在尋找一種方法來防止導出特定關係的外鍵的原則。例如:防止爲特定關係導出外鍵

Item: 
    connection: doctrine 
    #attributes: 
    # export: tables 
    columns: 
    store_id: integer(4) 
    shelf_id: integer(4) 
    relations: 
    Store: 
     local: store_id 
     foreign: id 
     foreignAlias: Items 
    Shelf: 
     local: shelf_id 
     foreign: id 
     foreignAlias: Items 

Shelf: 
    connection: doctrine 
    columns: 
    name: string(255) 

Store: 
    connection: store 
    columns: 
    name: string(255) 

在這裏,如果我建立這個模式,學說將產生項目表2個的外鍵:

ALTER TABLE item ADD CONSTRAINT item_store_id_store_id FOREIGN KEY (store_id) REFERENCES store(id); 
ALTER TABLE item ADD CONSTRAINT item_shelf_id_shelf_id FOREIGN KEY (shelf_id) REFERENCES shelf(id); 

如果取消註釋「屬性」部分,原則不會產生任何污染。因爲我只需要約束item_shelf_id_shelf_id。我想要它的原因是因爲Item和Shelf表位於同一個數據庫中,並且Store位於不同的數據庫中 - 外鍵不適用。

回答

0

假設您使用的是MySQL,此線程表示數據庫之間支持外鍵:http://forums.mysql.com/read.php?22,150829,200251#msg-200251所以問題可能在於生成的sql不包含數據庫名稱。 這些SQL建立Doctrine_Export::getForeignKeyBaseDeclaration,其中包含這些行:

 if (! isset($definition['foreignTable'])) { 
      throw new Doctrine_Export_Exception('Foreign reference table missing from definition.'); 
     } 

因此增加包含你的數據庫名稱在schema.yml中可能會有所幫助,如果數據庫是在同一臺服務器上foreignTable關鍵。

+0

我真的想讓它與數據庫無關。人們說他們在不同的數據庫中使用表格之間的關係,但我無法弄清楚正確的配置。 – Dziamid