我目前正在设计一个网站,使用 symfony (1.2) 和 Doctrine 作为 ORM。
我有一个晚餐类、一个标准类和一个标记类。
- Mark 与 Dinner 和 Criteria 相关联,并具有私有属性,如 DateOfMark、MarkValue 等。
- 晚餐和标准可以有很多标记(或没有)。
当我使用 Doctrine 时,我在我的 schema.yml 中定义了这个模型,使用以下代码:
Dinner:
columns:
date: { type: timestamp, notnull: true }
nb_presents: { type: integer, notnull: true }
relations:
Marks:
class: Criteria
local: dinner_id
foreign: criteria_id
refClass: Mark
Criteria:
columns:
name: { type: string(50), notnull: true }
relation:
Marks:
class: Dinner
local: criteria_id
foreign: dinner_id
refClass: Mark
Mark:
columns:
criteria_id: { type: integer, primary: true }
dinner_id: { type: integer, primary: true }
value: { type: integer, notnull: true }
relations:
Dinner:
local: dinner_id
foreign: id
Criteria:
local: criteria_id
foreign: id
问题是 Doctrine 生成的 SQL,它添加了一个 FOREIGN KEY CONSTRAINT
on Mark.dinner_id
to Dinner.id
(这是正确的)并且它添加了一个FOREIGN KEY CONSTRAINT
on Dinner.id
to Mark.dinner_id
(这真的不正确,因为晚餐可能有很多标记)。
问题
我错过了什么 ?我做错了类之间的这种关系吗?
谢谢。