Skip to content

Instantly share code, notes, and snippets.

@sergeylunev
Created October 25, 2012 11:33
Show Gist options
  • Save sergeylunev/3952109 to your computer and use it in GitHub Desktop.
Save sergeylunev/3952109 to your computer and use it in GitHub Desktop.
findSame
public function findSame($entity)
{
$qb = $this->getEntityManager()->createQueryBuilder();
$qb
->select('ar')
->from('AppAddressBundle:AddressRubric', 'ar')
->where('ar.address = :address')
->andWhere('ar.rubric = :rubric')
->andWhere('ar.id != :id')
->setParameter('address', $entity->getAddress())
->setParameter('rubric', $entity->getRubric())
->setParameter('id', $entity)
;
if ($tariff = $entity->getTariff()) {
$qb
->andWhere('ar.tariff = :tariff')
->setParameter('tariff', $tariff)
;
} else {
$qb
->andWhere('ar.tariff is null')
;
}
$qb->setMaxResults(1);
return $qb->getQuery()->getOneOrNullResult();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment