Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Symfony2][SF2] Pole Entity i wartość przekazywana do zapytania
skowron-line
post 19.04.2013, 13:58:05
Post #1





Grupa: Zarejestrowani
Postów: 4 340
Pomógł: 542
Dołączył: 15.01.2006
Skąd: Olsztyn/Warszawa

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


Mam coś takiego
  1. ->add('users_groups_id', 'entity',
  2. 'class' => 'i2\UserBundle\Entity\UserGroup',
  3. 'property' => 'name',
  4. )
  5. )

z formularza odbieram i przekazuje do encji User tak
  1. $em = $this->getDoctrine()->getEntityManager();
  2. $em->persist($form->getData());
  3. $em->flush();

i w wyniku dostaje takie zapytanie
  1. An exception occurred while executing 'INSERT INTO users (name, salary, birthdate, users_groups_id) VALUES (?, ?, ?, ?)' WITH params {"1":"skowron-line","2":5,"3":"2008-01-01","4":{}}:

Jako ostatni parametr podawany jest obiekt klasy UserGroup. Jak się ustawia żeby symfony2 wiedziało że ma sobie pobrać tyko id questionmark.gif

  1. /**
  2.  * @ORM\Entity
  3.  * @ORM\Table(name="users")
  4.  */
  5. class User {
  6. /**
  7.   * @ORM\Id
  8.   * @ORM\Column(name="id_users", type="integer")
  9.   * @ORM\GeneratedValue(strategy="AUTO")
  10.   */
  11. protected $id_users;
  12. /**
  13.   * @ORM\Column(name="name", type="string")
  14.   */
  15. protected $name;
  16. /**
  17.   * @ORM\Column(name="salary", type="decimal")
  18.   */
  19. protected $salary;
  20. /**
  21.   * @ORM\Column(name="birthdate", type="date")
  22.   */
  23. protected $birthdate;
  24. /**
  25.   * @ORM\Column(name="users_groups_id", type="smallint")
  26.   */
  27. public $users_groups_id;

i
  1. /**
  2.  * @ORM\Entity
  3.  * @ORM\Table("users_groups")
  4.  */
  5. class UserGroup {
  6.  
  7. /**
  8.   * @ORM\Id
  9.   * @ORM\Column(name="id_users_groups", type="smallint")
  10.   * @ORM\GeneratedValue(strategy="AUTO")
  11.   */
  12. protected $id_users_groups;
  13. /**
  14.   * @ORM\Column(name="name", type="string")
  15.   */
  16. protected $name;


Z góry dziękuje za odpowiedz


--------------------
I'm so fast that last night I turned off the light switch in my hotel room and was in bed before the room was dark - Muhammad Ali.
Peg jeżeli chcesz uprawiać sex to dzieci muszą wyjść, a jeżeli chcesz żeby był dobry ty też musisz wyjść - Al Bundy.

QueryBuilder, Mootools.net, bbcradio1::MistaJam
http://www.phpbench.com/
Go to the top of the page
+Quote Post

Posty w temacie


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: 19.07.2025 - 16:17