我在schema.yml(Symfony 1.4)中的Post模型如下所示:
Post:
columns:
id: { type: bigint, notnull: true, primary: true }
blog_id: { type: bigint, notnull: true, primary: true }
user_id: { type: bigint, notnull: true }
subject: { type: string(255), notnull: true }
short_body: { type: text, notnull: true }
long_body: { type: text }
如您所见,Post具有多列PK。我的问题是"如何与此模型创建 n:1 关系?
举个例子,我想要这样的东西:
PostComment:
columns:
post_id: { type: bigint, notnull: true }
blog_id: { type: bigint, notnull: true }
name: { type: string(255), notnull: true }
email: { type: string(255) }
text: { type: text, notnull: true }
relations:
Post:
#Here is my problem. What should I write here?
local: ????
foreign: ????
foreignAlias: Comments
onDelete: cascade
onUpdate: cascade
我如何处理这种类型的关系?
你不能。您可以向 Post 模型添加另一个主键,并将其他几个字段保持唯一。如果您这样做,我强烈建议将"id"作为您的主键,并使用另一个字段名称作为唯一字段名称以及"blog_id"。然后,只需像往常一样使用PostComment中的关系。