Doctrine2 / Symfony Cheat Sheet

Column Types

Date

 

Query Builder

andWhereIn

  • $qb->andWhere('user.name IN (:names)');
    $qb->setParameter('names', ['Karen', 'Kevin', 'Kim']);

offset / limit

  • $qb->setMaxResults($limit)
    $qb->setFirstResult($offset)
    

Use another repository in a repository

  • // in UserRepository.php
    $locations = $this->getEntityManager()->getRepository(Location::class) // without ...Repository!
        ->findDistinctLocations()

Caching

$query->setResultCacheId('my_custom_id');
// or shorter notation with lifetime option
$query->useResultCache(true, 3600, 'my_custom_id');

// to delete cache
$cacheDriver = $entityManager->getConfiguration()->getResultCacheImpl();
$cacheDriver->delete('my_custom_id');
// to delete all cache entries
$cacheDriver->deleteAll();