views:

41

answers:

1

Hi,

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?

+3  A: 

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.

jeremy
I have to admit that my example is a bad one. Despite the fact that it does not make much sense there my intention is to create a one to many relationship between a junction table and another table.
Ghommey