Php Doctrine/MySql与多列PK表的关系

Php Doctrine/MySql与多列PK表的关系,php,mysql,symfony1,doctrine,symfony-1.4,Php,Mysql,Symfony1,Doctrine,Symfony 1.4,我在schema.yml(Symfony 1.4)中的帖子模型如下所示: 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), no

我在schema.yml(Symfony 1.4)中的帖子模型如下所示:

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 }
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有一个多列PK。我的问题是“如何与该模型建立n:1关系?”

举个例子,我想要这样的东西:

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 }
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中的关系。

我不熟悉这种表示法,但您需要一对多。我猜postcomment也应该有它的id!谢谢你的回复。但另一个问题是,“如何在yml语法中创建多列唯一约束?”请参阅