EntityRepository and EntityManager have slightly different versions of the createQueryBuilder() function. Whereas the EntityManager’s version takes no arguments, EntityRepository’s version expects an ‘
$alias‘ parameter. What is going on?!
The EntityRepository class wraps the EntityManager’s call, as such:
The function’s phpdoc reveals the reasoning behind the parameter count differences, EntityRepository returns a version of createQueryBuilder() customised for itself. We no longer need to specify the primary table we’re selecting from. Instead we must supply an
$alias parameter which would usually be later supplied to the
Also note the above means all columns are selected from the entity by default.