Reputation: 9990
I have an entity:
...
class UserRole extends Role
{
/**
* @ORM\Column(name="user_role_id", type="integer")
* @ORM\Id()
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
...
But when I try to use user_role_id in a doctrine query I get this error:
[Semantical Error] line 0, col 42 near 'user_role_id': Error: Class MyApp\Model\UserRole has no field or association named user_role_id
The query I am using is this:
$query = $this->getEntityManager()
->createQuery('SELECT r FROM Model:UserRole AS r WHERE r.user_role_id IN (:roles)')
->setParameter('roles', array_values($roles));
I've definitely got a user_role_id field as I can see it in phpMyAdmin.
Does anyone have any idea why doctrine is not recognising it?
Upvotes: 0
Views: 910
Reputation: 4397
This is doctrine and you want to write a DQL not a SQL, and you need to use the field names as defined in entities not the column names.
So in your query just use r.id
instead of r.user_role_id
Take a look at DQL in Doctrine
Upvotes: 1