Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [Symfony][Symfony2] dostęp w szablonie do relacyjnej bazy danych
dragon7
post 31.07.2012, 13:25:23
Post #1





Grupa: Zarejestrowani
Postów: 51
Pomógł: 0
Dołączył: 1.10.2010

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


Mam klasę
  1. /**
  2.   * @ORM\Id
  3.   * @ORM\Column(type="integer")
  4.   * @ORM\GeneratedValue(strategy="AUTO")
  5.   */
  6. protected $id;
  7.  
  8. /**
  9.   * @ORM\Column(type="string", length=100)
  10.   */
  11. protected $section_name;
  12.  
  13. /**
  14.   * @ORM\OneToMany(targetEntity="Category", mappedBy="section_id")
  15.   */
  16. protected $categories;


relacyjną do niej

  1. /**
  2.   * @ORM\Id
  3.   * @ORM\Column(type="integer")
  4.   * @ORM\GeneratedValue(strategy="AUTO")
  5.   */
  6. protected $id;
  7.  
  8. /**
  9.   * @ORM\Column(type="string", length=100)
  10.   */
  11. protected $category_name;
  12.  
  13. /**
  14.   * @ORM\ManyToOne(targetEntity="Section", inversedBy="categories")
  15.   * @ORM\JoinColumn(name="section_id", referencedColumnName="id")
  16.   */
  17. protected $section;


gdy odwołuje się do pobranego rekordu z tabeli section i chcę wydobyć wszystkie kategorie, z którymi ta sekcja jest powiązania to otrzymuję


An exception has been thrown during the rendering of a template ("Notice: Undefined index: section_id in D:\server\www\magnetosfera\vendor\doctrine\lib\Doctrine\ORM\Persisters\BasicEntityPersister.php line 1280") in ::base.html.twig at line 13.


dorzucam jeszcze odwołanie w szablonie twig

  1. <td>
  2. {% for r in result.categories %}
  3. {{ r }}
  4. {% endfor %}
  5. </td>


Ten post edytował dragon7 31.07.2012, 13:25:44
Go to the top of the page
+Quote Post
greycoffey
post 31.07.2012, 19:51:01
Post #2





Grupa: Zarejestrowani
Postów: 320
Pomógł: 29
Dołączył: 3.04.2010

Ostrzeżenie: (20%)
X----


Kod
/**
  * @ORM\OneToMany(targetEntity="Category", mappedBy="section_id")
  */
protected $categories;


To jest mapowane przez właściwość section, nie przez section_id.
Go to the top of the page
+Quote Post
dragon7
post 31.07.2012, 20:24:58
Post #3





Grupa: Zarejestrowani
Postów: 51
Pomógł: 0
Dołączył: 1.10.2010

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


Wielkie dzięki:)
Go to the top of the page
+Quote Post
greycoffey
post 31.07.2012, 22:36:21
Post #4





Grupa: Zarejestrowani
Postów: 320
Pomógł: 29
Dołączył: 3.04.2010

Ostrzeżenie: (20%)
X----


Sam kilka dni temu rozwiązywałem ten sam problem wink.gif
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: 22.06.2025 - 12:50