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.