Suppose you want to do Many to Many relationship between an Event and a Image table using Doctrine; Each Event has a “main” Image list and a “other” list. Here’s the schema.yml:
Image:
columns:
id: { type: integer(4), fixed: false, unsigned: false, primary: true, autoincrement: true }
name: { type: string(), fixed: false, unsigned: false, primary: false, notnull: true, autoincrement: false }
relations:
Events: {class: Event, local: image_id, foreign: event_id, refClass: EventImages }
EventsMain: {class: Event, local: image_id, foreign: event_id, refClass: EventImagesMain }
EventsOther: {class: Event, local: image_id, foreign: event_id, refClass: EventImagesOther }
EventImages:
columns:
image_id: { type: integer(4), primary:true }
event_id: { type: integer(4), primary:true }
type: { type: enum, values: ["main", "other"], default: "main", notnull: true, primary:true }
relations:
Images : {local: image_id, foreign: id}
EventImagesMain:
inheritance:
extends: EventImages
type: column_aggregation
keyField: type
keyValue: main
EventImagesOther:
inheritance:
extends: EventImages
type: column_aggregation
keyField: type
keyValue: other
Event:
columns:
id: { type: integer(4), fixed: false, unsigned: false, primary: true, autoincrement: true }
name: { type: string(), fixed: false, unsigned: false, primary: false, notnull: true, autoincrement: false }
relations:
Images: { class: Image, local: event_id, foreign: image_id, refClass: EventImages }
OtherImages: { class: Image, local: event_id, foreign: image_id, refClass: EventImagesOther }
MainImages: { class: Image, local: event_id, foreign: image_id, refClass: EventImagesMain }
In order for methods like $image->getEventsMain() and $event->getMainImages() to work, you need to define the relations for all of the tables involved (Image, EventImages, Event).
Knowing this beforehand would have saved me around five hours of tinkering with the schema.
Hope this helps.