Php 对此,我将使用什么查询
我有一个联系老师和学生的关系表Php 对此,我将使用什么查询,php,database,orm,doctrine,propel,Php,Database,Orm,Doctrine,Propel,我有一个联系老师和学生的关系表 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语法 $re
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;
}
问题是我最终得到的是一个数组,而不是通常的propelCollection,当我们执行normal->find时得到的。有没有一种方法可以稍微清理一下这个查询,然后使用连接或类似的东西,这样我就可以从一开始就得到一个PropelCollection?您应该像这样定义关系的模式: 您要求的代码非常简单:
$teacher = TeacherQuery::create()->findOneById($teacherId);
$students = $teacher->getStudents(); //Your students collection