【发布时间】:2012-06-18 09:46:59
【问题描述】:
我在 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
我该如何处理这种类型的关系?
【问题讨论】:
-
我不熟悉这种表示法,但您需要一对多。我猜postcomment也应该有它的ID!
标签: php mysql symfony1 doctrine symfony-1.4