I have a many-to-many relationship, and when I load an object that is on the one hand, this relationship, I expect to see its ArrayCollection property of related objects on the other hand. However, this does not happen - there are no elements in the loaded ArrayCollection array, while in the database I see related records. What could be the reason?
Here is my code:
One side of the relationship, the ConsolidatedReport class:
/** * @var ArrayCollection * * @ORM\ManyToMany(targetEntity="P24\Response", inversedBy="consolidatedReports") * @ORM\JoinTable(name="con_rprt_responses") */ private $responses;
The other side of the relationship, the response class:
private $consolidatedReports;
Here is the function that I run to get an instance of ConsolidatedReport. This function is inside the service called from the container:
public function pick($id) { $report = $this->repository->findOneBy(array('id' => $id)); if (!$report) { throw new NonExistentConsolidatedReportException($id); } return $report; }'
The database has a table called "con_rprt_responses" with two columns, "united_reports_id" and "response_id". However, in the profiler, I do not see any queries on this table.
What could go wrong here?
UPDATE: Please see my answer to this question below, which worked for me.
source share