Skip to content

Instantly share code, notes, and snippets.

@jacobsenj
Created December 12, 2013 13:29
Show Gist options
  • Save jacobsenj/7927932 to your computer and use it in GitHub Desktop.
Save jacobsenj/7927932 to your computer and use it in GitHub Desktop.
Repository Method to get MAX + 1 of a number field within the entity
namespace Application\Repository;
use Application\Entity\Name;
use Doctrine\ORM\EntityRepository;
class NameRepository
extends EntityRepository
{
/**
* @return int
*/
public function getNextNumber()
{
return $this->getEntityManager()->createQuery('SELECT MAX(n.number) + 1 AS number FROM Application\Entity\Name n')->getSingleScalarResult();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment