2011-03-17 10 views
0

我是Symfony的新手,嘗試通過構建模型然後構建sql來創建數據庫結構。在Symfony中使用YAML創建的關係(與Doctrine)沒有在MySQL數據庫中填充

所有的表都出現在數據庫中,但是不會創建簡單的一對多關係以外的關係。

例如我有一個存儲公司的表,他們既可以是供應商也可以是客戶,我有另一個存儲客戶/供應商關係的表。

Identifier: 
    actAs: [Timestampable] 
    tableName: identifier 
    columns: 
    id: 
     type: integer(20) 
     fixed: false 
     unsigned: false 
     primary: true 
     autoincrement: true 
    relations: 
    Suppliers: 
     class: Identifier 
     local: customer_id 
     foreign: supplier_id 
     refClass: CustomerSupplier 
     foreignAlias: Customers 
     onDelete: CASCADE 
    Customers: 
     class: Identifier 
     local: supplier_id 
     foreign: customer_id 
     refClass: CustomerSupplier 
     foreignAlias: Suppliers 
     onDelete: CASCADE 
CustomerSupplier: 
    actAs: [Timestampable] 
    tableName: customerSupplier 
    columns: 
    id: 
     type: integer(20) 
     fixed: false 
     unsigned: false 
     primary: true 
     autoincrement: true 
    customer_id: 
     type: integer(20) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: true 
     autoincrement: false 
    supplier_id: 
     type: integer(20) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: true 
     autoincrement: false 

一比一的關係,不會創建或者:

IdentifierExtCompany: 
    actAs: [Timestampable] 
    tableName: identifierExtCompany 
    columns: 
    identifier_id: 
     type: integer(20) 
     fixed: false 
     unsigned: false 
     primary: true 
     autoincrement: true 
    relations: 
    Identifier: 
     local: identifier_id 
     foreign: id 
     onDelete: CASCADE 
     foreignType: one 
     type: one 

所有這些關係不會當我運行通過構建-SQL生成的SQL請求出現在數據庫中。

你能幫我檢測我的yaml文件有什麼問題嗎?在此先感謝

+1

您使用的是MyISAM嗎?你究竟在MySQL中稱之爲「關係」?外鍵? N:M表? – greg0ire 2011-03-17 09:16:36

回答

0

例如我有一個表存儲公司,他們既可以是供應商也可以是客戶,我有另一個表存儲客戶/供應商關係。

好像你必須定義關係,爲CustomerSupplier太:

relations: 
    IdentifierAlias: 
    class: Identifier 
    local: identifier_id 
    onDelete: CASCADE 
    SupplierAlias: 
    class: Supplier 
    local: supplier_id 
    onDelete: CASCADE 

一比一的關係,不會創建任何

嘗試在關係指定class屬性,將其設置爲Identifier

希望這會有所幫助。

+0

感謝您的回覆,我找到了解決方法。不知道爲什麼,當我運行'doctrine:build-model'後面跟着'doctrine:build-sql'和'doctrine:insert-sql'時,關係沒有正確填充。當我運行'doctrine:build --all --no-confirmation'時它工作得很好 – Andy 2011-03-22 08:24:47

相關問題