I have entity Patients with a field
/**
*
* @ORM\OneToOne(targetEntity="Surgery\LoginBundle\Entity\User" , mappedBy="patient")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
protected $user;
I want to get foreign key from Patiens ,so I created that query
$query = $em->createQuery('SELECT p.user_id FROM SurgeryPatientBundle:Patients p WHERE p.user =5 ');
I get this error
[Semantical Error] line 0, col 9 near 'user_id FROM': Error: Class Surgery\PatientBundle\Entity\Patients has no field or association named user_id '
My question it’s can I get to that field without create JOIN ?
Try this:
or