我将对此使用什么查询

| 我有一张
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;
}
问题在于,我最终得到的是数组,而不是正常的“ 5”时得到的通常的propelCollection。有没有一种方法可以稍微清理此查询(使用联接之类的方法),以便从一开始就以PropelCollection结尾?     
已邀请:
您应该为这种关系定义模式,如下所示:http://www.propelorm.org/wiki/Documentation/1.5/Relationships#Many-to-ManyRelationships 您要的代码非常简单:
$teacher = TeacherQuery::create()->findOneById($teacherId);
$students = $teacher->getStudents(); //Your students collection
    

要回复问题请先登录注册