【发布时间】:2015-04-12 20:02:36
【问题描述】:
如果有三个实体:Students、Classes和Topics,它们之间的关系如下:
Student <-> Class: many-to-many(一个学生上多个班级,一个班级有多个学生上)
Class <-> Topic: many-to-many(一个类涉及多个主题,一个主题涉及多个类)
使用 Doctrine 我很容易实现 $student->getClasses() 或 $class->getTopics()。
实现$student->getTopics() 的最佳方式是什么?
以下工作,但似乎不正确正确:
public function getTopics()
{
$topics = array();
foreach ($student->getClasses() as $class) {
$topics = array_merge($topics, $class->getTopics());
}
return array_unique($topics);
}
【问题讨论】: