Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Problem z JOIN LEFT: Doctrine_Table_Exception: Unknown relation alias
Forum PHP.pl > Forum > Bazy danych > MySQL
tejek
Witam,

Od pewnego czasu męczę się z MySql, Doctrine i JOINLEFT. Mój plik schema.yml wygląda tak: (w zasadzie jest to kawałek tego pliku. Plik generuje przy pomocy WorkBench-a)

  1. ---
  2. detect_relations: true
  3. options:
  4. collate: utf8_polish_ci
  5. charset: utf8
  6. type: InnoDB
  7.  
  8. User:
  9. tableName: Users
  10. COLUMNS:
  11. id:
  12. type: integer(4)
  13. PRIMARY: true
  14. notnull: true
  15. autoincrement: true
  16. username:
  17. type: string(45)
  18. notnull: true
  19. password:
  20. type: string(45)
  21. notnull: true
  22. email:
  23. type: string(45)
  24. notnull: true
  25. phone:
  26. type: string(100)
  27. notnull: true
  28. type:
  29. type: enum
  30. VALUES: ['u','a']
  31. DEFAULT: 'u'
  32. active:
  33. type: integer(1)
  34. DEFAULT: 0
  35. blocked:
  36. type: integer(1)
  37. DEFAULT: 0
  38. options:
  39. charset: utf8
  40. collate: utf8_polish_ci
  41.  
  42. UsersDetail:
  43. tableName: UsersDetails
  44. COLUMNS:
  45. user_detail_id:
  46. type: integer(4)
  47. PRIMARY: true
  48. notnull: true
  49. autoincrement: true
  50. Users_id:
  51. type: integer(4)
  52. notnull: true
  53. name:
  54. type: string(45)
  55. surname:
  56. type: string(45)
  57. address:
  58. type: string(255)
  59. city:
  60. type: string(45)
  61. postcode:
  62. type: string(45)
  63. birthdate:
  64. type: string(45)
  65. relations:
  66. User:
  67. class: User
  68. LOCAL: Users_id
  69. FOREIGN: id
  70. foreignAlias: UsersDetails
  71. options:
  72. charset: utf8
  73. collate: utf8_polish_ci


Natomiast moje zapytanie do bazy wygląda następująco:
  1. $data = Doctrine_Query::create()->from('Model_User u')->select('u.*,d.*')
  2. ->leftJoin('u.Model_UsersDetail d ON d.Users_id=u.id')
  3. ->fetchArray();


Co robię źle, że wyrzuca mi taki błąd: Doctrine_Table_Exception: Unknown relation alias Model_UsersDetail??
toffiak
Nie widzę nigdzie klas Model_User i Model_UsersDetail
spróbuj tak
  1. $data = Doctrine_Query::CREATE()->select('u.*,d.*')->from('User u')->leftJoin('u.UsersDetail d')
  2. ->fetchArray();
tejek
To nie będzie to, nazwy class modeli są poprawne, bo podczas generowania Modeli dodaje do każdej nazwy tabeli która jest pobierana z pliku yml przedrostek Model_ dlatego nazwy się różnią.

Jednak mam pytanie, a zarazem prośbę czy mógłby ktoś sprawdzić czy w moim pliku .yml poprawnie zadeklarowałem relacje. W sumie plik .yml tworzyłem przy pomocy workbench-a jednak maszyny też się czasem mylą, a ja już to przeglądam nie chyba 100 raz i wydaje mi się że wszystko jest ok ;/

Bo gdy wykonuje zapytania:
  1. $data = Doctrine_Query::create()->from('Model_User u')->select('u.*')
  2. ->fetchArray();

lub
  1. $data = Doctrine_Query::create()->from('Model_UsersDetail d')->select('d.*')
  2. ->fetchArray();


to otrzymuje poprawne wyniki, jednak gdy dodam:
->leftJoin('u.Model_UsersDetail d ON d.Users_id=u.id')
to wszystko się sypie ;/

Proszę pomóżcie.
Daniel_K
Witam, mam identyczny problem... toffiak - nalazłeś może jakieś rozwiązanie? Bo sprawdzałem już wszystko i nadal Doctrine_Table_Exception: Unknown relation alias ...
pain3hp
myślę że trzeba ręcznie zrobić relacje w klasach które są zmapowane, jednak nie jestem pewny
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.