Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Symfony][Symfony2][Doctrine2]Natywny sql problem z zapytaniem zwraca null
silverwind
post
Post #1





Grupa: Zarejestrowani
Postów: 80
Pomógł: 0
Dołączył: 8.02.2013

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


Dlaczego mi zwraca null przy natywny sql w zapytaniu. Dump w szablonie są same null.

  1. public function getExpensesByProperty()
  2. {
  3.  
  4. $rsm = new ResultSetMapping;
  5.  
  6. $rsm->addEntityResult('User\UserBundle\Entity\User', 'u');
  7.  
  8. $rsm->addFieldResult('u', 'username', 'username');
  9.  
  10. $sql = "
  11. SELECT username
  12. FROM users
  13.  
  14. ";
  15.  
  16.  
  17.  
  18.  
  19. $query= $this->_em->createNativeQuery(
  20. $sql, $rsm
  21. );
  22.  
  23.  
  24.  
  25. return $query->getResult();
  26.  
  27. }
  28. }
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
silverwind
post
Post #2





Grupa: Zarejestrowani
Postów: 80
Pomógł: 0
Dołączył: 8.02.2013

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


Teraz mam problem ze SUMĄ . W ogóle ją nie wyświetla
  1. public function getExpensesByProperty()
  2. {
  3.  
  4. $rsm = new ResultSetMapping;
  5.  
  6. $rsm->addEntityResult('User\UserBundle\Entity\User', 'u');
  7.  
  8. $rsm->addFieldResult('u', 'username', 'username');
  9. $rsm->addFieldResult('u', 'id', 'id');
  10. $rsm->addJoinedEntityResult('Property\ManagementBundle\Entity\Owner' , 'o', 'u', 'owners');
  11. $rsm->addFieldResult('o', 'o_id', 'id');
  12. $rsm->addFieldResult('o', 'o_name', 'name');
  13. $rsm->addJoinedEntityResult('Property\ManagementBundle\Entity\Property' , 'p', 'o', 'property');
  14. $rsm->addFieldResult('p', 'p_id', 'id');
  15. $rsm->addFieldResult('p', 'p_name', 'name');
  16. $rsm->addFieldResult('p', 'p_adress', 'adress');
  17. $rsm->addJoinedEntityResult('Property\ManagementBundle\Entity\Expenses' , 'e', 'p', 'expenses');
  18. $rsm->addFieldResult('e', 'e_id', 'id');
  19. $rsm->addFieldResult('e', 'e_name', 'name');
  20. $rsm->addFieldResult('e', 'e.price', 'price');
  21. $sql = "
  22. SELECT u.id,u.username,
  23. o.id as o_id,o.name as o_name,
  24. p.id as p_id,p.name as p_name,p.adress as p_adress,
  25. e.id as e_id,e.name as e_name,SUM(e.price) as SUMA
  26. FROM users u
  27. INNER JOIN owner o ON u.id = o.user_id
  28. INNER JOIN property p ON o.id=p.owner_id
  29. LEFT JOIN expenses e ON p.id=e.property_id
  30. GROUP BY p_id
  31. ";
  32.  
  33.  
  34.  
  35.  
  36. $query= $this->_em->createNativeQuery(
  37. $sql, $rsm
  38. );
  39.  
  40. // $query->setParameter(1,$User);
  41.  
  42. return $query->getArrayResult();
  43.  
  44. }
  45. }
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 14.10.2025 - 03:14