Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 对此,我将使用什么查询_Php_Database_Orm_Doctrine_Propel - Fatal编程技术网

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