As a newbie in Symfony2 & doctrine i'm struggling (in a custom repository class) with the difference between getEntityManager()
and getManager()
.
I know getEntityManager()
is being deprecated but if I use getManager()
instead, I'm getting "Undefined method 'getManager'. The method name must start with either findBy or findOneBy!"
In my class, the following code works:
public function haalidop($verbid)
{
return $this->getEntityManager()
->createQuery('SELECT p FROM myBundle:Verbs p WHERE p.verbid='.$verbid)
->getSingleResult();
}
If I change (upgrade?) it like the code below, I get the error...
public function haalidop($verbid)
{
return $this->getManager()
->createQuery('SELECT p FROM myBundle:Verbs p WHERE p.verbid='.$verbid)
->getSingleResult();
}
Anyone any suggestion what's wrong here?
The getEntityManager
method of the Registry
is deprecated. Since you're in a Repository, you extended not the Registry but the EntityRepository
. That class has only a getEntityManager
method, which isn't deprecated.
The reason for this inconsistency is quite easy: The Registry is something that's used for other Doctrine library too, like their ODMs. They don't use the name "Entity", but "Document". For that reason, using getEntityManager
didn't make much sense for ODMs, that's why they changed if to getManager
.
On the other hand, the EntityRepository
-as its name already tells us- is ORM specific, meaning there is no confusing for ODM users (they use another repository class).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With