让我们看看这个架构:
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不应该设置外键?
答案 0 :(得分: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 :(得分: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)任务来创建模式: / p>
symfony propel:build-schema