Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getEntityManager() and getDoctrine() in Symfony2

Is there any difference between these two statements:

$this->getDoctrine()->getEntityManager()->getRepository();

$this->getDoctrine()->getRepository();

Does the difference relate to any OOP concept I am missing out?

like image 803
NightOwl85 Avatar asked Nov 29 '11 18:11

NightOwl85


1 Answers

In general, no difference, since

$this->getDoctrine()->getRepository();

is just a helper for

$this->getDoctrine()->getEntityManager()->getRepository();

You can have several entity managers, and then there will be a slight difference in getting a repository from one:

$this->getDoctrine()->getRepository($entityName, $enityManagerName);
$this->getDoctrine()->getEntityManager($entityManagerName)->getRepository($entityName);

But again, no difference in the result you'll get.

All other things being equal, I'd go with the shortest one.

like image 184
Elnur Abdurrakhimov Avatar answered Sep 20 '22 17:09

Elnur Abdurrakhimov