Mam w Doctrine 2 2 klasy:
class Conversation { /** * @Id @GeneratedValue @Column(type="integer") * @var int */ protected $id; /** * ManyToMany(targetEntity="User", inversedBy="conversations") * @JoinTable(name="users_conversations") * @var User[] **/ protected $users = null; public function __construct() { $this->users = new ArrayCollection(); } //... }
oraz
class User { /** * @Id @GeneratedValue @Column(type="integer") * @var int */ protected $id; /** * @ManyToMany(targetEntity="Conversation", mappedBy="users") * @var Conversation[] **/ protected $conversations; public function __construct() { $this->conversations = new ArrayCollection(); } //... }
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:
$conversation = $this->_em->find( '\src\Conversation', 1 ); $users = $conversation->getUsers();
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.