Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Symfony] Doctrine i left joiny
blackroger
post 5.05.2011, 14:02:39
Post #1





Grupa: Zarejestrowani
Postów: 176
Pomógł: 0
Dołączył: 8.11.2008

Ostrzeżenie: (0%)
-----


witam. jest sobie takie cos:

  1. return Doctrine_Core::getTable('Article')->createQuery('a')
  2. ->leftJoin('a.Translation t')
  3. ->leftJoin('a.Gallery g')
  4. ->leftJoin('g.Translation t2')
  5. ->where('t.lang = ?', $lang)
  6. ->addWhere('a.f_menu = ?', $this->getTId())
  7. ->addWhere('t2.lang = ?', $lang)
  8. ->orderBy('a.t_position')
  9. ->execute();


Przy zrzucie na toArray:

  1. (
  2. [0] => Array
  3. (
  4. [t_id] => 7
  5. [f_menu] => 10
  6. [f_article_type] =>
  7. [f_user] =>
  8. [t_latitude] =>
  9. [t_longitude] =>
  10. [t_position] => 7
  11. [d_created_at] => 2011-05-05 13:47:01
  12. [d_modified_at] =>
  13. [Translation] => Array
  14. (
  15. [pl] => Array
  16. (
  17. [t_id] => 7
  18. [t_title] =>
  19. [e_content] =>
  20. )
  21.  
  22. )
  23.  
  24. [Gallery] => Array
  25. (//i tu jest pusto chociaz zapytanie zwraca wyniki
  26. )
  27.  
  28. )
  29.  
  30. )





Zapytanie z debuggera:
  1. SELECT a.t_id AS a__t_id, a.f_menu AS a__f_menu, a.f_article_type AS a__f_article_type, a.f_user AS a__f_user, a.t_latitude AS a__t_latitude, a.t_longitude AS a__t_longitude, a.t_position AS a__t_position, a.d_created_at AS a__d_created_at, a.d_modified_at AS a__d_modified_at, a2.t_id AS a2__t_id, a2.t_title AS a2__t_title, a2.e_content AS a2__e_content, a2.lang AS a2__lang, a2.slug AS a2__slug, g.t_id AS g__t_id, g.t_filename AS g__t_filename, g.t_extension AS g__t_extension, g.f_gallery_type AS g__f_gallery_type, g.f_menu AS g__f_menu, g.f_article AS g__f_article, g.f_comment AS g__f_comment, g.f_news AS g__f_news, g.t_path AS g__t_path, g.t_size AS g__t_size, g.t_x_size AS g__t_x_size, g.t_y_size AS g__t_y_size, g.t_position AS g__t_position, g.d_created_at AS g__d_created_at, g.d_modified_at AS g__d_modified_at, g2.t_id AS g2__t_id, g2.t_desc AS g2__t_desc, g2.t_tip AS g2__t_tip, g2.lang AS g2__lang, g2.slug AS g2__slug FROM article a LEFT JOIN article_translation a2 ON a.t_id = a2.t_id LEFT JOIN gallery g ON a.t_id = g.f_article LEFT JOIN gallery_translation g2 ON g.t_id = g2.t_id WHERE (a2.lang = 'pl' AND a.f_menu = '10' AND g2.lang = 'pl') ORDER BY a.t_position


Co robię nie tak że Doctrine nie widzi tej tabeli gallery?

Go to the top of the page
+Quote Post
webdice
post 5.05.2011, 14:08:39
Post #2


Developer


Grupa: Moderatorzy
Postów: 3 045
Pomógł: 290
Dołączył: 20.01.2007




Dodaj:

Kod
->select( 'g.column' )
Go to the top of the page
+Quote Post
blackroger
post 5.05.2011, 16:52:40
Post #3





Grupa: Zarejestrowani
Postów: 176
Pomógł: 0
Dołączył: 8.11.2008

Ostrzeżenie: (0%)
-----


hmmm....to nic nie dało :/
W sumie zawsze mnie to męczyło....Można wziąć relację jeden do wielu w tą stronę w Doctrine w ogóle?

teraz chcę żeby to szło tak: article(1)->Gallery(wiele)
bo tak chodzi bez zarzutu gallery->article....problem jest w drugą stronę....zastanawiam się jakby wyglądała prezentacja tego w obiekcie, bo wywołując powiedzmy article->getGallery() zwracałoby wszystkie zdjęcia z galerii. hmm....

z tego co widzę takie pobranie obiektów może być tylko wtedy gdy wywołanie będzie jednoznaczne....tzn....getGallery() zwróci tylko i wyłącznie jeden obiekt....

Ten post edytował blackroger 5.05.2011, 17:22:06
Go to the top of the page
+Quote Post
janek9
post 5.05.2011, 17:20:54
Post #4





Grupa: Zarejestrowani
Postów: 121
Pomógł: 2
Dołączył: 22.03.2009

Ostrzeżenie: (0%)
-----


może tak? :

CODE
return Doctrine_Query::create()
->select(a.*,g.*,t.*,t2.*)
->from(Article a)
->leftJoin('a.Translation t')
->leftJoin('a.Gallery g')
->leftJoin('g.Translation t2')
->where('t.lang = ?', $lang)
->addWhere('a.f_menu = ?', $this->getTId())
->addWhere('t2.lang = ?', $lang)
->orderBy('a.t_position')
->execute();
Go to the top of the page
+Quote Post
blackroger
post 5.05.2011, 17:30:56
Post #5





Grupa: Zarejestrowani
Postów: 176
Pomógł: 0
Dołączył: 8.11.2008

Ostrzeżenie: (0%)
-----


nadal nic....

zauważyłem ponadto że to zapytanie:

  1.  
  2. return Doctrine_Core::getTable('Article')->createQuery('a')
  3. ->leftJoin('a.Translation t')
  4. ->leftJoin('a.Gallery g')
  5. ->leftJoin('g.Translation t2')
  6. ->where('t.lang = ?', $lang)
  7. ->addWhere('a.f_menu = ?', $this->getTId())
  8. ->addWhere('t2.lang = ?', $lang)
  9. ->orderBy('a.t_position')
  10. ->execute();


wykonuje 6 zapytań.....coś jest nie tak....

  1.  
  2. #
  3.  
  4. SELECT a.t_id AS a__t_id, a.f_menu AS a__f_menu, a.f_article_type AS a__f_article_type, a.f_user AS a__f_user, a.t_latitude AS a__t_latitude, a.t_longitude AS a__t_longitude, a.t_position AS a__t_position, a.d_created_at AS a__d_created_at, a.d_modified_at AS a__d_modified_at, a2.t_id AS a2__t_id, a2.t_title AS a2__t_title, a2.e_content AS a2__e_content, a2.lang AS a2__lang, a2.slug AS a2__slug, g.t_id AS g__t_id, g.t_filename AS g__t_filename, g.t_extension AS g__t_extension, g.f_gallery_type AS g__f_gallery_type, g.f_menu AS g__f_menu, g.f_article AS g__f_article, g.f_comment AS g__f_comment, g.f_news AS g__f_news, g.t_path AS g__t_path, g.t_size AS g__t_size, g.t_x_size AS g__t_x_size, g.t_y_size AS g__t_y_size, g.t_position AS g__t_position, g.d_created_at AS g__d_created_at, g.d_modified_at AS g__d_modified_at, g2.t_id AS g2__t_id, g2.t_desc AS g2__t_desc, g2.t_tip AS g2__t_tip, g2.lang AS g2__lang, g2.slug AS g2__slug FROM article a LEFT JOIN article_translation a2 ON a.t_id = a2.t_id LEFT JOIN gallery g ON a.t_id = g.f_article LEFT JOIN gallery_translation g2 ON g.t_id = g2.t_id WHERE (a2.lang = 'pl' AND a.f_menu = '10' AND g2.lang = 'pl') ORDER BY a.t_position
  5. 0.00s, "doctrine" connection
  6. #
  7.  
  8. SELECT g.t_id AS g__t_id, g.t_filename AS g__t_filename, g.t_extension AS g__t_extension, g.f_gallery_type AS g__f_gallery_type, g.f_menu AS g__f_menu, g.f_article AS g__f_article, g.f_comment AS g__f_comment, g.f_news AS g__f_news, g.t_path AS g__t_path, g.t_size AS g__t_size, g.t_x_size AS g__t_x_size, g.t_y_size AS g__t_y_size, g.t_position AS g__t_position, g.d_created_at AS g__d_created_at, g.d_modified_at AS g__d_modified_at, g2.t_id AS g2__t_id, g2.t_desc AS g2__t_desc, g2.t_tip AS g2__t_tip, g2.lang AS g2__lang, g2.slug AS g2__slug FROM gallery g LEFT JOIN gallery_translation g2 ON g.t_id = g2.t_id WHERE (g2.lang = 'pl' AND g.f_article = '7') ORDER BY g.t_position
  9. 0.00s, "doctrine" connection
  10.  
  11. ....
  12. ...
  13. .
  14. .
  15. .
  16. powyższe zapytanie jeszcze kilka razy....tak jakby dla kazdego article
  17.  


Go to the top of the page
+Quote Post
janek9
post 5.05.2011, 17:43:46
Post #6





Grupa: Zarejestrowani
Postów: 121
Pomógł: 2
Dołączył: 22.03.2009

Ostrzeżenie: (0%)
-----


najlepiej będzie jak podasz zawartość pliku schema.yml.

Wtedy pomyślimy dalej.

Ten post edytował janek9 5.05.2011, 17:44:05
Go to the top of the page
+Quote Post
blackroger
post 5.05.2011, 17:58:16
Post #7





Grupa: Zarejestrowani
Postów: 176
Pomógł: 0
Dołączył: 8.11.2008

Ostrzeżenie: (0%)
-----


Dobra przepraszam wszystkich za zamieszanie....wszystko działa. Okazało się, że w klasie Article mam nadpisaną metodę getGallery, która z automatu pobierała elementy Gallery i mieszała....w każdym bądź razie teraz wszystko ładnie działa smile.gif

Ten post edytował blackroger 5.05.2011, 18:34:38
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 25.06.2025 - 21:45