Ignas Damunskis
Ignas Damunskis

Reputation: 1504

Symfony2 / Doctrine: select() and getResults() doens't work with getManager()

I have this problem... When I try to use getEntityManager() it is said that it's depricated. Seems it's not usable in newer Symfony2 versions.

Now when I use getManager() it is said that select() and getQuery() can't be found in class. Any ideas how to manage this? BTW, I'm working in a controller.

$em = $this->getDoctrine()->getManager();
$queryBuilder = $em->createQueryBuilder();

$queryBuilder->select('Project')
    ->from('ProjectProjectBundle:Profiles', 'Project')
    ->where('Project.email', $data['email']);

$profile = $queryBuilder->getQuery()->getResult();

Upvotes: 0

Views: 297

Answers (1)

Bactisme
Bactisme

Reputation: 1683

I think, it's a best practice to go through repository instead of configuring the queryBuilder

Check something like this :

$em = $this->getDoctrine()->getManager();
$project_repo = $em->getRepository('ProjectProjectBundle:Profiles');

$profile = $project_repo->createQueryBuilder('project')
        ->where('project.email = :email')
        ->setParameter('email', $data['email'])            
        ->getQuery()->getResult();

Upvotes: 2

Related Questions