【发布时间】:2011-04-13 21:53:59
【问题描述】:
我有一个 Relationship 表,将教师与学生联系起来
Teacher Student
1 1
1 2
2 1
2 3
Students 表有关于学生的具体数据
Id Date of birth First Name
1 1990-10-10 Bill Smith
2 1989-01-03 Adam Smithson
我想选择老师 1 的所有学生。现在我这样做(这是推进 ORM 语法)。
$relationships = RelationshipQuery::create()->filterByTeacher($teacherid)->find();
foreach($relationships as $relationship){
$studentId = $relationship->getStudent();
//use the studentId to get the actual student object
$student = StudentQuery::create()->findPk($studentId);
//after I get the student, I add it to an array
$students[] = $student;
}
问题在于我最终得到了一个数组,而不是我们在执行普通->find() 时最终得到的通常的 propelCollection。有没有办法稍微清理一下这个查询(使用连接或类似的东西),以便我从一开始就得到一个 PropelCollection?
【问题讨论】:
标签: php database orm doctrine propel