Доктрина Symfony множественного левого присоединения Query - PullRequest
1 голос
/ 24 сентября 2010

Я пытаюсь выполнить этот запрос и получаю ошибку " Неизвестные псевдонимы программ ".это запрос.

$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.Есть ли простой способ?

Ответы [ 2 ]

3 голосов
/ 24 сентября 2010

Вы можете легко попробовать ваш dql, используя доктрину командной строки symfony: 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);
0 голосов
/ 24 сентября 2010

В вашем ответе была небольшая ошибка, greg, если вы видите функцию выбора, каждое имя столбца разделяется запятой, это должно быть так ..

$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);
...