【问题标题】:Doctrine: Relating a model to itself using a link table, like "This event is related to to the following other events"原则:使用链接表将模型与自身相关联,例如“此事件与以下其他事件相关”
【发布时间】:2011-05-31 10:15:16
【问题描述】:

所以在英语中,这种关系听起来像“这个事件与以下其他事件有关”。

我的第一反应是创建一个EventEvent 模型,其中包含一个first_event_id 字段和一个second_event_id 字段。然后我会在Event模型中定义以下两个关系:

$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'));

但我宁愿不必在 Event 模型上使用两个关系。有没有更好的方法来做到这一点?

【问题讨论】:

    标签: php database-design doctrine doctrine-1.2 object-relational-model


    【解决方案1】:

    我在手册中找到了:Equal Nest Relations

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-24
      • 1970-01-01
      • 2012-07-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多