Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Added ability to specify INDEX BY when creating a QueryBuilder from a Repository #592

wants to merge 1 commit into from

6 participants

Craig Menning doctrinebot Benjamin Eberlei Johnny Robeson Marco Pivetta Jonathan Langevin
Craig Menning

This is a handy shortcut when using indexed results.



thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

Benjamin Eberlei

I think this is enough to be available through $entityManager->createQueryBuilder()->from()

Benjamin Eberlei beberlei closed this March 12, 2013
Craig Menning

In DoctrineBundle, however,


has been deprecated, which leaves you to use


Adding ->from() at that point is redundant since it's already been specified inside the createQueryBuilder() call. It seems wasteful to not allow a passthru of the $indexBy argument during the initial call when it's already supported by the from() called inside createQueryBuilder().

Johnny Robeson

i agree with @cmenning : any way you can reconsider @beberlei?

Johnny Robeson

i was going to submit the exact same feature request btw. but @cmenning actually did a PR.

Marco Pivetta

What's the problem in doing following?

$qb = $em->createQueryBuilder()->select('e')->from($repo->getClassName(), 'e', 'e.stuff')?

The repository already does more than needed (imo)

Craig Menning

I don't think it's out of scope for the Repository, which by definition in the Doctrine docs "provides many ways to retrieve entities of the specified type". It makes sense to allow it to specify the index for the results.

In a Symfony controller, for example, these are functionally equivalent:

    ->from($repo->getClassName(), 'e', 'e.stuff');


    ->createQueryBuilder('e', 'e.stuff');

This has the following benefits:

  • More concise
  • Doesn't require as much manual query building
  • In line with very common ways of getting objects from the database ($repo->find($criteria))
  • Is more logical from an object-oriented point of view: you start with a collection of objects (the Repository) and not a database connection (the EntityManager)
Jonathan Langevin

Agreed with @cmenning, this PR ought to be reconsidered @beberlei

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Feb 27, 2013
Craig Menning Added ability to specify INDEX BY when creating a QueryBuilder from a…
… Repository
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 2 additions and 2 deletions. Show diff stats Hide diff stats

  1. 4  lib/Doctrine/ORM/EntityRepository.php
4  lib/Doctrine/ORM/EntityRepository.php
@@ -78,11 +78,11 @@ public function __construct($em, Mapping\ClassMetadata $class)
78 78
79 79
      * @return QueryBuilder
80 80
-    public function createQueryBuilder($alias)
+    public function createQueryBuilder($alias, $indexBy = null)
82 82
83 83
         return $this->_em->createQueryBuilder()
84 84
-            ->from($this->_entityName, $alias);
+            ->from($this->_entityName, $alias, $indexBy);
86 86
87 87
88 88

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.