Symfony1 条令symfony多个leftjoin查询

Symfony1 条令symfony多个leftjoin查询,symfony1,doctrine,Symfony1,Doctrine,我正在尝试运行此查询,并收到错误“未知关系别名程序””。 这就是问题所在 $q= Doctrine_Query::create() ->select('students.firstname', 'students.middlename', 'students.lastname', 'programs.program',

我正在尝试运行此查询,并收到错误“未知关系别名程序””。 这就是问题所在

$q= Doctrine_Query::create()
             ->select('students.firstname',
                      'students.middlename',
                      'students.lastname',
                      'programs.program',
                      'courses.title',
                      'programcourses.year')
             ->from('students s, s.programs p, p.programcourses p2, p2.courses c');
我也试过这个

$q= Doctrine_Query::create()
             ->select('students.firstname',
                      'students.middlename',
                      'students.lastname',
                      'programs.program',
                      'courses.title',
                      'programcourses.year')
             ->from('students')
             ->leftJoin('programs')
             ->leftJoin('programcourses')
             ->leftJoin('courses')
             ->where("idstudents=".$studentid);
这是我的Schema.yml

  Courses:
  connection: doctrine
  tableName: courses
  columns:
    idcourses:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
    title:
      type: string(45)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
  relations:
    Programcourses:
      local: idcourses
      foreign: idcourses
      type: many
Programcourses:
  connection: doctrine
  tableName: programcourses
  columns:
    idprogramcourses:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
    idprograms:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    idcourses:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    year:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
  relations:
    Courses:
      local: idcourses
      foreign: idcourses
      type: one
    Programs:
      local: idprograms
      foreign: idprograms
      type: one
Programs:
  connection: doctrine
  tableName: programs
  columns:
    idprograms:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: false
    program:
      type: string(45)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
  relations:
    Programcourses:
      local: idprograms
      foreign: idprograms
      type: many
    Students:
      local: idprograms
      foreign: idprograms
      type: many
Roles:
  connection: doctrine
  tableName: roles
  columns:
    idroles:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: false
    role:
      type: string(45)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
Students:
  connection: doctrine
  tableName: students
  columns:
    idstudents:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
    firstname:
      type: string(45)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    middlename:
      type: string(45)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    lastname:
      type: string(45)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    idprograms:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    session:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    username:
      type: string(45)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    password:
      type: string(45)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    email:
      type: string(255)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
  relations:
    Programs:
      local: idprograms
      foreign: idprograms
      type: one
Teachers:
  connection: doctrine
  tableName: teachers
  columns:
    idteachers:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
    firstname:
      type: string(45)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    lastname:
      type: string(45)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    username:
      type: string(45)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    password:
      type: string(45)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    email:
      type: string(255)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false

还有mysql到dql的转换工具吗?首先进行mysql查询,然后将这些查询更改为dql。有一种简单的方法吗?

您可以使用命令行symfony-doctor:dql轻松地尝试您的dql 现在,在查询中,关系程序是小写的,而在模式中是大写的。 如果我是你,我会尝试这样的东西:

$q= Doctrine_Query::create()
             ->select('s.firstname,
                      s.middlename,
                      s.lastname,
                      p.program,
                      c.title,
                      pc.year')
             ->from('Students s')
             ->leftJoin('s.Programs p')
             ->leftJoin('p.Programcourses pc')
             ->leftJoin('pc.Courses')
             ->where("idstudents = ?", $studentid);

在你的回答中有一个小错误greg,如果你能看到select函数,每个列名都用逗号分隔,应该是这样的

$q= Doctrine_Query::create()
         ->select('s.firstname,
                  s.middlename,
                  s.lastname,
                  p.program,
                  c.title,
                  pc.year')
         ->from('Students s')
         ->leftJoin('s.Programs p')
         ->leftJoin('p.Programcourses pc')
         ->leftJoin('pc.Courses c')
         ->where("idstudents = ".$studentid);

这些连接应该有关系的大写名称。另外,您不必将$studentid作为数组进行转换。我今天的回答太快了。谢天谢地,你在这里:)谢谢greg..现在工作了,但我很困惑..我在phpbb中创建了我的数据库..所有的关系都是小写的..然后我从这个数据库生成了schema.yml..在phpbb中我仍然有小写的关系名..那么为什么symfony使用这种约定呢?。。idstudents=?意思?问号是参数的占位符(本例中为studentid)。我准备了一份声明。看看这是什么:在条件严重的情况下使用这种风格!通过这样做,您就可以传递PDO,并且它带来的所有好处(如防止SQL注入!)都已修复。我绝对应该睡一觉。