Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Symfony][SF2][Symfony2] createNativeQuery + join i subquery -problem z mapowaniem
adamantd
post 15.05.2015, 13:05:13
Post #1





Grupa: Zarejestrowani
Postów: 228
Pomógł: 7
Dołączył: 15.08.2012
Skąd: Rzeszów

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


Witam, nie mogę sobie poradzić ze zmapowaniem Joina:

  1.  
  2. $rsm = new ResultSetMapping;
  3. $rsm->addEntityResult('AccountClientBundle:SearchQuestionConnect', 'c');
  4. $rsm->addFieldResult('c', 'c_id', 'id');
  5. $rsm->addFieldResult('c', 'c_distance', 'distance');
  6. $rsm->addJoinedEntityResult('AccountClientBundle:SearchQuestionConnectPriceComment', 'sq', 'c', 'search_question_connect_id'); //Z TYM JEST CAŁY CZAS PROBLEM
  7. $rsm->addFieldResult('sq', 'sq_id', 'id');
  8. $rsm->addMetaResult('sq', 'sq_search_question_connect_id', 'search_question_connect_id');
  9.  
  10.  
  11. $q = $this->getEntityManager()->createNativeQuery("
  12. SELECT
  13. c.id AS c_id,
  14. c.distance AS c_distance,
  15. sq.id AS sq_id,
  16. sq.search_question_connect_id AS sq_search_question_connect_id
  17. FROM search_question_connects AS c
  18. JOIN (SELECT * FROM search_question_connect_price_comments ORDER BY created_at DESC) AS sq ON (sq.search_question_connect_id=c.id)
  19. WHERE
  20. c.search_id = {$searchId}
  21. AND c.status_bidder = 2
  22. GROUP BY c.id
  23. ORDER BY sq.created_at DESC
  24. ", $rsm);
  25. $r = $q->getResult();
  26.  
  27.  


Ciągle wyskakuje mi:

  1. Notice: Undefined index: search_question_connect_id


bez wzgledu na to co podam jako ostatni parametr dla

  1. $rsm->addJoinedEntityResult()


to zawsze jest ten sam błąd tylko zmienia się oczywiście

  1. Undefined index w zależności od tego jaka jest wartość tego parametru


Jeżeli usunę 3 ostatnie linijki
  1. $rsm->

to zapytanie wykonuje się tak jak tego oczekuję -potrzebuję jednak dołączyć wyniki drugiej tabeli

Będe wdzięczny za pomoc
Go to the top of the page
+Quote Post
prz3kus
post 15.05.2015, 14:46:11
Post #2





Grupa: Zarejestrowani
Postów: 260
Pomógł: 30
Dołączył: 22.01.2007

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


Pole search_question_connect_id istnieje w klasie entity?
Go to the top of the page
+Quote Post
adamantd
post 15.05.2015, 14:55:00
Post #3





Grupa: Zarejestrowani
Postów: 228
Pomógł: 7
Dołączył: 15.08.2012
Skąd: Rzeszów

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




  1. /**
  2.   * @ORM\ManyToOne(targetEntity="SearchQuestionConnect", inversedBy="searchQuestionConnectPriceComments")
  3.   * @ORM\JoinColumn(name="search_question_connect_id", referencedColumnName="id",onDelete="CASCADE")
  4.   **/
  5. private $searchQuestionConnect;
Go to the top of the page
+Quote Post
prz3kus
post 15.05.2015, 14:58:10
Post #4





Grupa: Zarejestrowani
Postów: 260
Pomógł: 30
Dołączył: 22.01.2007

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


No to w joinie chyba trzba podać searchQuestionConnect, a nie search_question_connect_id
Go to the top of the page
+Quote Post
adamantd
post 15.05.2015, 14:59:13
Post #5





Grupa: Zarejestrowani
Postów: 228
Pomógł: 7
Dołączył: 15.08.2012
Skąd: Rzeszów

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


Testuje -nie pomaga

  1. Notice: Undefined index: searchQuestionConnect
Go to the top of the page
+Quote Post
prz3kus
post 15.05.2015, 15:00:26
Post #6





Grupa: Zarejestrowani
Postów: 260
Pomógł: 30
Dołączył: 22.01.2007

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


$rsm->addMetaResult('sq', 'sq_search_question_connect_id', 'search_question_connect_id');

tutaj tez trzeba zmienic smile.gif
Go to the top of the page
+Quote Post
adamantd
post 15.05.2015, 15:05:33
Post #7





Grupa: Zarejestrowani
Postów: 228
Pomógł: 7
Dołączył: 15.08.2012
Skąd: Rzeszów

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


Chciałbym smile.gif ale niestety -wszystkie możliwe kombinacje po kolei i nic ...

  1.  
  2. $rsm->addJoinedEntityResult('AccountClientBundle:SearchQuestionConnectPriceComment', 'sq', 'c', 'searchQuestionConnect');
  3. $rsm->addFieldResult('sq', 'sq_id', 'id');
  4. // $rsm->addMetaResult('sq', 'sq_search_question_connect_id', 'search_question_connect_id');
  5. //$rsm->addMetaResult('sq', 'sq_searchQuestionConnect', 'search_question_connect_id');
  6. $rsm->addMetaResult('sq', 'searchQuestionConnect', 'search_question_connect_id');
  7.  



tutaj też:

  1.  
  2. $q = $this->getEntityManager()->createNativeQuery("
  3. SELECT
  4. c.id AS c_id,
  5. c.distance AS c_distance,
  6. c.offer_id AS c_offer_id,
  7. sq.id AS sq_id,
  8. sq.search_question_connect_id AS searchQuestionConnect
  9.  
Go to the top of the page
+Quote Post
prz3kus
post 18.05.2015, 07:05:06
Post #8





Grupa: Zarejestrowani
Postów: 260
Pomógł: 30
Dołączył: 22.01.2007

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


Poczytaj dokumentacje(o ile jeszcze nie zrobikles) ciągle źle podmieniasz smile.gif

Tak to powinno wyglądać:

  1. $rsm->addJoinedEntityResult('AccountClientBundle:SearchQuestionConnectPriceComment', 'sq', 'c', 'searchQuestionConnect');
  2. $rsm->addFieldResult('sq', 'sq_id', 'id');
  3. // $rsm->addMetaResult('sq', 'sq_search_question_connect_id', 'search_question_connect_id');
  4. //$rsm->addMetaResult('sq', 'sq_searchQuestionConnect', 'search_question_connect_id');
  5. $rsm->addMetaResult('sq', 'search_question_connect_id', 'searchQuestionConnect');



  1. $q = $this->getEntityManager()->createNativeQuery("
  2. SELECT
  3. c.id AS c_id,
  4. c.distance AS c_distance,
  5. c.offer_id AS c_offer_id,
  6. sq.id AS sq_id,
  7. sq.search_question_connect_id AS search_question_connect_id


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: 28.04.2024 - 08:51