Symfony 6 Doctrine relationship self-referencing uni-directional with linking table doesn't return data

Viewed 42

Please let me assure you I could not find response anywhere, maybe there is one, but I was unable to locate it.

What I want to do is self-referencing relationship but with LINKING TABLE because I find them easier to read than self referencing foreign key. So I used the only example of this I found in Doctrine documentation

So here it is, this is class User which implements Userinterface too (Manager and Employee is just a USER with different roles)

 /**
 * Manager can have many employees
 * @ORM\ManyToMany(targetEntity="User", mappedBy="managers")
 */
private $employees;
/**
 * Employee can have many managers
 * @ORM\ManyToMany(targetEntity="User", inversedBy="employees")
 * @ORM\JoinTable(
 *     name="manager_employee",
 *     joinColumns={@ORM\JoinColumn(name="employeeId", referencedColumnName="id")},
 *     inverseJoinColumns={@ORM\JoinColumn(name="managerId", referencedColumnName="id")}
 * )
 */
private $managers;

Now the problem is - I am 99% positive I loaded my fixtures with Managers who have multiple employees and 99% positive I use getEmployees on a correct manager. I quinduple checked. Yet when I use this method I get empty collection. I dumped collection, I checked with Xdebug. Empty. Why? I have them in DB, db works flawlessly. There must be something wrong with this relationship part but its beyond me to think of any more reason.

I would be grateful for your help, I would not have asked if it was not my last resort. Thank you!

0 Answers
Related