Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Doctrine 2.1 - relacja OneToMany oraz ściąganie danych
Jazi
post
Post #1





Grupa: Zarejestrowani
Postów: 122
Pomógł: 2
Dołączył: 25.08.2009
Skąd: Toruń / Bydgoszcz

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


Mam dwie klasy:

User:

  1. /** @Entity @Table(name="users") */
  2. class User {
  3. /**
  4.   * @Id @GeneratedValue @Column(type="integer")
  5.   * @var integer
  6.   */
  7. protected $id;
  8.  
  9. /**
  10.   * @Column(type="string", length=20, unique=TRUE)
  11.   * @var string
  12.   */
  13. protected $login;
  14.  
  15. /**
  16.   * @OneToMany(targetEntity="News", mappedBy="author")
  17.   */
  18. protected $news;
  19.  
  20. public function __construct() {
  21. $this->news = new \Doctrine\Common\Collections\ArrayCollection;
  22. }
  23. }


i News:

  1. /** @Entity @Table(name="news") */
  2. class News {
  3. /**
  4.   * @Id @GeneratedValue @Column(type="integer")
  5.   * @var integer
  6.   */
  7. protected $id;
  8.  
  9. /**
  10.   * @Column(type="string", length=100)
  11.   * @var string
  12.   */
  13. protected $title;
  14.  
  15. /**
  16.   * @Column(type="text")
  17.   * @var string
  18.   */
  19. protected $content;
  20.  
  21. /**
  22.   * @ManyToOne(targetEntity="User", inversedBy="news")
  23.   * @JoinColumn(referencedColumnName="id")
  24.   */
  25. protected $author;
  26. }


Czy po wykonaniu poniższego kodu

  1. $q = $this->db->createQuery('SELECT u FROM User u WHERE u.id = '.$id);
  2. $user = $q->getSingleResult();


Doctrine ściągnie wszystkie aktualności (stworzone przez konkretnego użytkownika) z bazy danych?

Ten post edytował Jazi 15.12.2011, 18:39:34
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 Aktualny czas: 20.08.2025 - 18:18