2012-01-15 47 views
0

讓我們來看看這個模式:Symfony的1.4行走:我確定,但外鍵沒有在表中定義

orders: 
    _attributes: { phpName: Orders, default_table_charset: utf8, default_table_collate: utf8_general_ci } 
    id:    ~ 
    category_id: { type: integer, size: '10', required: true, defaultvalue: '0', foreigntable: categories, foreignreference: id } 
    whatisthis:  { type: longvarchar, required: false } 

    categories: 
    _attributes: { phpName: Categories } 
    id:   ~ 
    name:  { type: varchar, size: '255', required: true, defaultvalue: '' } 
    _uniques: { index_name: [name] } 

我想通了,外鍵並不在我的表中定義。我使用innoDB所以PK是可能的。或者Propel不應該設置外鍵?

回答

3

的 「foreingtable」 和 「foreignreference」 應該是駱駝套管。而category_id的大小應該與類別的id大小相等。

orders: 
    _attributes: { phpName: Orders, default_table_charset: utf8, default_table_collate: utf8_general_ci } 
    id:    ~ 
    category_id: { type: integer, size: '10', required: true, defaultvalue: '0', foreignTable: categories, foreignreRerence: id } 
    whatisthis:  { type: longvarchar, required: false } 

    categories: 
    _attributes: { phpName: Categories } 
    id:   ~ 
    name:  { type: varchar, size: '255', required: true, defaultvalue: '' } 
    _uniques: { index_name: [name] } 
1

您正在使用哪個symfony和propel版本?

假設正在使用波輪1.x中,在這裏你是一個一對多的關係,例如:


    musician: 
    _attributes: { phpName: Musician } 
    id: { phpName: Id, type: INTEGER, size: '9', primaryKey: true, autoIncrement: true, required: true } 
    #other fields 
    musician_album: 
    _attributes: { phpName: MusicianAlbum } 
    id: { phpName: Id, type: INTEGER, size: '9', primaryKey: true, autoIncrement: true, required: true } 
    musician_id: { phpName: MusicianId, type: INTEGER, size: '9', required: true, foreignTable: musician, foreignReference: id, onDelete: CASCADE, onUpdate: CASCADE } 
    #other fields 
    _indexes: { musician_id: [musician_id] } 

說實話,我更喜歡手動創建數據庫表(設置,索引,外鍵和等等),然後我使用symfony(假設您使用Symfony 1.x)任務來創建模式:

symfony propel:build-schema