2

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

このタイプの関係をどのように処理できますか?

4

1 に答える 1

1

できません。Post モデルに別の主キーを追加し、別のいくつかのフィールドを一意に保つことができます。その場合は、「id」を主キーにし、「blog_id」とともに別のフィールド名を一意として使用することを強くお勧めします。次に、PostComment から通常どおりリレーションを使用します。

于 2012-06-18T18:52:07.163 に答える