Reputation: 6997
am trying to create one to many relation, below is my 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 }
the problem am facing is with the sql generated. The above yml is building a constraint on both table meanwhile I only want the constraint to be built for City table. Any idea how can I do that?
Regards,
Upvotes: 0
Views: 2954
Reputation: 4871
Set foreign
to id
, because by default Doctrine considers primary keys called id
until you set it manually in schema. Also, I would manually set relation type in schema (or in model, as mentioned by @benlumney):
relations:
Country:
local: country_code
foreign: id # or you can just skip this param in this case
class: Country
type: many
foreignType: one
Upvotes: 2