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
 
Start new topic
Odpowiedzi
-=Peter=-
post
Post #2





Grupa: Zarejestrowani
Postów: 304
Pomógł: 51
Dołączył: 4.02.2005
Skąd: Kraków

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


Np. iterowanie po kolekcji.
Go to the top of the page
+Quote Post
michael1986
post
Post #3





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 19.09.2005

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


Cytat(-=Peter=- @ 10.01.2012, 23:24:01 ) *
Np. iterowanie po kolekcji.


a jak zrobić taką iterację? Prosze o przykład, teraz użwam ->toArray i foreach po tablicy i wydaje mi się że jest to dość wolne.
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: 20.09.2025 - 20:24