jantimon
jantimon

Reputation: 38140

Doctrine: 1 to many relationship with multiple foreign keys

I am using Doctrine 1.2 and looking for the correct syntax for creating a 1:n relationship between two tables in my schema.yml

Usual this is done by:

BookChapter:
  columns:
    ...
  relations:
    Book:
      class: Book
      local: book_id
      foreign: id
      type: one
      onDelete: cascade

However in my special case there are 2 foreign primary keys.

BookReader

book:
  type: integer(8)
  primary: true
reader: 
  type: integer(8)
  primary: true


BookReaderDetails

book_id: integer(8)
reader_id: integer(8)
...

Is it possible to define such a relation with a doctrine schema file?

Upvotes: 2

Views: 1982

Answers (1)

Jeremy Kauffman
Jeremy Kauffman

Reputation: 10413

Doctrine doesn't play nicely with multiple primary keys unless they are being used as a many-to-many reference table (junction table).

If you want a 1-to-many relation and not many-to-many, you're probably best off adding a primary key column to BookReader. You can then put a unique index on book and reader.

Upvotes: 3

Related Questions