Fork me on GitHub

Doctrine QueryBuilder

Provide return types for Method calls

Root Entity

Every querybuilder object need to have a root entity, some provider are in

// PhpTypeProvider
$repository = $foo->getRepository('BundleName');
$qb = $repository->createQueryBuilder('test')->addSelect('test');

// \Doctrine\Common\Persistence\ObjectRepository
class FooRepository extends EntityRepository {
    public function foo() {
      $qb = $this->createQueryBuilder('foo_alias');
    }
}

// \Doctrine\ORM\QueryBuilder::from
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->from('Foo\Class', 'foo')

// inline
$qb = $em->getRepository('FooBundle:FooEntity')->createQueryBuilder('foo')

// chaining
$qb = $this>getMyQueryBuilder()->addSelect('');
../_images/querybuilder-select.png

Supported Calls

$qb->select('job');
$qb->select(array('job', 'dependencies'));

$qb->addSelect('job');
$qb->addSelect(array('job', 'dependencies'));

$qb->setParameter('foo');
$qb->setParameters(array('foo' => 'bar'));

$qb->join('foo.bar', 'bar');
// and all other joins

$qb->groupBy('foo.bar');
$qb->addGroupBy('foo.bar');

$qb->orderBy('foo.bar');
$qb->addOrderBy('foo.bar');

$qb->where('foo.bar');
$qb->andWhere('foo.bar');
$qb->orWhere('foo.bar');