2010-04-28 38 views
0

我有一個MySQL 5.1.41數據庫,我試圖以填補原則,但原則不能正確地插入關係。我YAML是:主義並不出口關係正確

Locatie: 
connection: doctrine 
tableName: locatie 
    columns: 
    loc_id: 
    type: integer(4) 
    fixed: false 
    unsigned: false 
    primary: true 
    autoincrement: true 
    org_id: 
    type: integer(4) 
    fixed: false 
    unsigned: false 
    primary: false 
    notnull: false 
    autoincrement: false 
    naam: 
    type: string(30) 
    fixed: false 
    unsigned: false 
    primary: false 
    notnull: true 
    autoincrement: false 
    straat: 
    type: string(30) 
    fixed: false 
    unsigned: false 
    primary: false 
    notnull: true 
    autoincrement: false 
    huisnummer: 
    type: integer(4) 
    fixed: false 
    unsigned: false 
    primary: false 
    notnull: true 
    autoincrement: false 
    huisnummer_achtervoegsel: 
    type: string(3) 
    fixed: false 
    unsigned: false 
    primary: false 
    notnull: false 
    autoincrement: false 
    plaats: 
    type: string(25) 
    fixed: false 
    unsigned: false 
    primary: false 
    notnull: true 
    autoincrement: false 
    postcode: 
    type: string(6) 
    fixed: false 
    unsigned: false 
    primary: false 
    notnull: true 
    autoincrement: false 
    telefoon: 
    type: string(12) 
    fixed: false 
    unsigned: false 
    primary: false 
    notnull: true 
    autoincrement: false 
    opmerking: 
    type: string() 
    fixed: false 
    unsigned: false 
    primary: false 
    notnull: false 
    autoincrement: false 
    inloggegevens: 
    type: string() 
    fixed: false 
    unsigned: false 
    primary: false 
    notnull: false 
    autoincrement: false 
relations: 
    Organisatie: 
    local: org_id 
    foreign: org_id 
    type: one 
    onDelete: CASCADE 
    onUpdate: CASCADE 

Organisatie: 
    connection: doctrine 
    tableName: organisatie 
    columns: 
    org_id: 
     type: integer(4) 
     fixed: false 
     unsigned: false 
     primary: true 
     autoincrement: true 
    naam: 
     type: string(30) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: true 
     autoincrement: false 
    straat: 
     type: string(30) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: true 
     autoincrement: false 
    huisnummer: 
     type: integer(4) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: true 
     autoincrement: false 
    huisnummer_achtervoegsel: 
     type: string(3) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: false 
     autoincrement: false 
    plaats: 
     type: string(25) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: true 
     autoincrement: false 
    postcode: 
     type: string(6) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: true 
     autoincrement: false 
    telefoon: 
     type: string(12) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: true 
     autoincrement: false 
    opmerking: 
     type: string(255) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: false 
     autoincrement: false 
    relations: 
    Locatie: 
     local: org_id 
     foreign: org_id 
     type: many 

現在,如果您的組織,然後創建具有外鍵來組織一切的位置是好的。但是當我嘗試更新與phpmyadmin的org_id我得到一個約束錯誤。如果我手動將外鍵設置爲ON_UPDATE CASCADE,它確實有效。

爲什麼教義沒有設置這個選項?

我得到了它在行走工作,但我真的想用教義這一點。

回答

0

好,因爲它是由位置表引用您不能更新org_id。如果你改變它,這意味着組織有一個不存在的位置---外鍵失敗。首先插入您的位置數據,然後所有位置值成爲組織的可能值,或者如您所述使用onCascade操作。

此外,有些東西你可以做的是先定義Organisatie表,包括關係的聲明僅適用於該表(一個定義是足夠的學說)。現在Locatie表被引用,並且您可以隨意使用其鍵。當然,你仍然不能引用Organisatie表中不存在的東西。

我還發現您的模式現在說,「一個組織有許多地方」,但我猜你已經打算「一個地方有很多的組織」。如果確實如此,請將Organisatie-> relations-> Locatie更改爲「type:one,foreignType:many」,然後從Locatie表中刪除關係聲明。

希望有所幫助。