I am trying in Symfony 6 to join two tables by one relational column, where one table has OneToMany relation to the other.
This is my controller logic
#[Route('/admin/patients', name: 'app_patients')]
public function patients(PatientsRepository $patients, EntityManagerInterface $entityManager): Response
{
$query = $entityManager->createQuery(
'SELECT patients, patientsInfo
FROM AppEntityPatients patients
JOIN AppEntityPatientsInformation patientsInfo
WHERE patientsInfo.patientID = patients.id'
);
$data = $query->getResult();
return $this->render('main/tables.html.twig', ['data' => $data]);
}
my twig template
{% for item in data %}
<tr>
<td>{{ item.patient.id }}</td>
<td><i class="fas fa-user-nurse fs-5"></i> {{ item.patient.name }}</td>
<td>{{ item.patientsInfo.nationality }}</td>
<td>{{ item.patient.unhcrID }}</td>
<td>No</td>
<td>{{ item.patient.creationDate|date('Y-m-d') }}</td>
<td>None</td>
<td>
<a class="btn btn-primary" role="button">More</a>
<a class="btn btn-danger" role="button">Delete</a>
</td>
</tr>
{% endfor %}
The error it throws is
Neither the property “patient” nor one of the methods “patient()”, “getpatient()”/”ispatient()”/”haspatient()” or “__call()” exist and have public access in class “AppEntityPatients”.