原则:使用链接表将模型与其自身相关联,例如“此事件与以下其他事件相关”
因此,在英语中,这种关系听起来就像“此事件与以下其他事件相关”。
我的第一反应是创建一个 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
模型上使用两个关系。有更好的方法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在手册中找到了它: 平等嵌套关系
I found it in the manual: Equal Nest Relations