My Post model in schema.yml (Symfony 1.4) looks like this:
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 }
as you can see Post has a multi-column PK. My question is “How can I create n:1 relationship with this model?”
As an example, I want something like this:
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
How can I handle this type of relationship?
You can’t.
You can add another primary key to your Post model, and keeping another couple of fields as unique. If you do so, I strongly advice to make “id” your primary key and use another field name as unique along with “blog_id”.
Then, just use relations as usual from PostComment.