2010-09-14 40 views
2

我正在構建一個schema.yml,我試圖將外鍵約束添加到表sf_guard_user。但是,當我做doctrine:insert-sql(edit:doctrine:build --all)時,我的表和sf_guard_user之間的鏈接就不存在了!我錯過了什麼嗎?使用sfDoctrineGuardPlugin的schema.yml

我用mysql(InnoDB的)和Symfony的1.4

這裏是我的schema.yml樣本:

Author: 
    connection: doctrine 
    tableName: ec_author 
    actAs: 
    Sluggable: 
     fields: [name] 
     unique: true 
     canUpdate: false 
    columns: 
    sf_guard_user_id: 
     type: integer 
     fixed: false 
     unsigned: false 
     primary: true 
     autoincrement: false 
    name: 
     type: string(30) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: true 
     autoincrement: false 
    contents: 
     type: string() 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: false 
     autoincrement: false 
    relations: 
     User: 
     class: sfGuardUser 
     foreignType: one 
     local: sf_guard_user_id 
     foreign: id 

有到sfGuardUser沒有任何聯繫,即使他們中描述的schema.yml: alt text alt text

+0

您使用的是什麼數據庫引擎? – greg0ire 2010-09-14 16:23:01

+0

我在Mysql上使用InnoDB。 – Manu 2010-09-17 10:10:23

+0

Manu,BaseAuthor類中存在關係嗎?是否有打電話給$ this-> hasOne('sfGuardUser ...'? – 2010-09-18 16:18:36

回答

2

這一個工程:

Author: 
    connection: doctrine 
    tableName: ec_author 
    actAs: 
    Sluggable: 
     fields: [name] 
     unique: true 
     canUpdate: false 
    columns: 
    sf_guard_user_id: 
     type: integer 
     fixed: false 
     unsigned: false 
     primary: false 
     autoincrement: false 
    name: 
     type: string(30) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: true 
     autoincrement: false 
    contents: 
     type: string() 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: false 
     autoincrement: false 
    relations: 
     User: 
     class: sfGuardUser 
     foreignType: one 
     local: sf_guard_user_id 
     foreign: id 
     foreignAlias: author 

sf_guard_user_id是一個外鍵,那麼它可以」 t是主鍵。所以我將 primary: true更改爲primary: false

+0

順便說一句,您的表ec_author中將有一個名爲id的主鍵。它是自動生成的(如果您沒有明確聲明主鍵)。 – 2010-09-21 15:19:06

+0

它的工作原理!最後!我愛你 :) – Manu 2010-09-22 07:37:48

1

您應該重建模型和SQL也。試試運行:

symfony doctrine:build --all 

這將痛毆現有的所有數據。如果你不想這樣做,你必須寫一個遷移。

+0

+1 insert-sql只是插入schema.sql文件,如果你不重新生成它,它不會工作。 – greg0ire 2010-09-17 10:51:51

+0

即使構建 - 所有的鏈接都不存在。我應該改變插件內的schema.yml ? – Manu 2010-09-17 12:29:54

+0

當你說鏈接不存在時,它們在哪裏丟失?它是否在SQL中丟失(即從sf_guard_user_id到sf_guard_user表中沒有FK)?BaseAuthor是否將sf_guard_user_id添加到用戶的關係? – 2010-09-17 14:37:01

1

在您的模式文件中打開相應的表時,類名稱需要與您指定的名稱相同。

因此,舉例來說,使用的是:

relations: 
    User: 
     class: sfGuardUser 
     foreignType: one 

類的名字在這裏必須sfGuardUser表的聲明相匹配。只要確定他們是一樣的。有時候,它可以被聲明爲sf_guard_user。

如果是罰款,你可以嘗試增加一些定義你的關係條目:

relations: 
    User: 
     class: sfGuardUser 
     foreignType: one 
     local: sf_guard_user_id 
     foreign: sf_guard_user_id 
+0

感謝您的回答,我已經添加了您的建議,但鏈接仍然不存在:( – Manu 2010-09-21 13:12:39

+0

能夠填充表格?當您嘗試添加不存在的FK時,是否會導致FK錯誤? – jgallant 2010-09-21 13:29:18

相關問題