Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP][MySQL] Doctrine - ManyToMany
sweter
post
Post #1





Grupa: Zarejestrowani
Postów: 623
Pomógł: 11
Dołączył: 1.01.2009
Skąd: Wrocław

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


Cześć,
Mam w Doctrine 2 2 klasy:
  1. class Conversation
  2. {
  3. /**
  4.   * @Id @GeneratedValue @Column(type="integer")
  5.   * @var int
  6.   */
  7. protected $id;
  8.  
  9. /**
  10.   * ManyToMany(targetEntity="User", inversedBy="conversations")
  11.   * @JoinTable(name="users_conversations")
  12.   * @var User[]
  13.   **/
  14. protected $users = null;
  15.  
  16. public function __construct()
  17. {
  18. $this->users = new ArrayCollection();
  19. }
  20. //...
  21. }

oraz
  1. class User
  2. {
  3. /**
  4.   * @Id @GeneratedValue @Column(type="integer")
  5.   * @var int
  6.   */
  7. protected $id;
  8.  
  9. /**
  10.   * @ManyToMany(targetEntity="Conversation", mappedBy="users")
  11.   * @var Conversation[]
  12.   **/
  13. protected $conversations;
  14.  
  15. public function __construct()
  16. {
  17. $this->conversations = new ArrayCollection();
  18. }
  19. //...
  20. }

wykonałem php ./vendor/bin/doctrine orm:schema:tool update --force, wstawiłem przykładowe dane i próbuję zczytać użytkowników przypisanych do konwersacji:
  1. $conversation = $this->_em->find(
  2. '\src\Conversation',
  3. 1
  4. );
  5.  
  6. $users = $conversation->getUsers();
  7.  
  8. var_dump(count($users));

Jednak var_dump() wypisuje mi 0, mimo że powinien wypisać 2.
Dlaczego tak się dzieje? Czyżbym źle napisał adnotacje w komentarzach.
Proszę o wyjaśnienie, bo nie znam dobrze Doctrine, a siedzę nad tym problemem już jakiś czas.

Ten post edytował sweter 20.07.2013, 15:19:55


--------------------
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 Aktualny czas: 21.08.2025 - 07:39