我正在尝试创建一对多关系,下面是我的yml sechma
Country:
actAs:
Timestampable: ~
I18n:
fields: [country_name]
columns:
country_code: { type: string(30), notnull:true, unique: true }
country_name: { type: string(200), notnull:true }
country_flag: { type: string(200), notnull: flase }
created_by: {type: bigint, notnull: true }
updated_by: {type: bigint, notnull: false }
relations:
sfGuardUser1: { local: created_by, foreign: id, class: sfGuardUser }
sfGuardUser2: { local: updated_by, foreign: id, class: sfGuardUser }
City:
actAs:
Timestampable: ~
I18n:
fields: [city_name]
columns:
city_name: { type: string(100), notnull: true }
country_code: { type: integer, notnull: true }
created_by: {type: bigint, notnull: true }
updated_by: {type: bigint, notnull: false }
relations:
Country:
local: country_code
foreign: country_code
class: Country
sfGuardUser1: { local: created_by, foreign: id, class: sfGuardUser }
sfGuardUser2: { local: updated_by, foreign: id, class: sfGuardUser }
我面临的问题是生成的sql。上面的yml正在构建两个表的约束,同时我只想为City表构建约束。知道我该怎么办?
此致
答案 0 :(得分:2)
将foreign
设置为id
,因为默认情况下,Doctrine会将主键称为id
,直到您在架构中手动设置它为止。另外,我会手动设置模式中的关系类型(或者在模型中,如@benlumney所述):
relations:
Country:
local: country_code
foreign: id # or you can just skip this param in this case
class: Country
type: many
foreignType: one