Doctrine: Relating a model to itself using a link table, like "This event is related to to the following other events"
Posted
by
mattalexx
on Stack Overflow
See other posts from Stack Overflow
or by mattalexx
Published on 2010-12-28T04:21:22Z
Indexed on
2010/12/28
4:54 UTC
Read the original article
Hit count: 259
So in English, the relationship would sound like "This event is related to to the following other events".
My first instinct is to create an EventEvent
model, with a first_event_id
field and a second_event_id
field. Then I would define the following two relationships in the Event
model:
$this->hasMany('Event as FirstRelatedEvents', array('local' => 'first_event_id', 'foreign' => 'second_event_id', 'refClass' => 'EventEvent'));
$this->hasMany('Event as SecondRelatedEvents', array('local' => 'second_event_id', 'foreign' => 'first_event_id', 'refClass' => 'EventEvent'));
But I would rather not have to use two relationships on the Event
model. Is there a better way to do this?
© Stack Overflow or respective owner