Skip to content

Instantly share code, notes, and snippets.

@bjunc
Last active August 11, 2017 02:39
Show Gist options
  • Save bjunc/596081c25eb9497f8b25739f8b37a5f5 to your computer and use it in GitHub Desktop.
Save bjunc/596081c25eb9497f8b25739f8b37a5f5 to your computer and use it in GitHub Desktop.
lightweight Symfony entity query with alias
// lightweight retrieval of orgId from alias
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery('SELECT org.oid FROM AppBundle:Organization org WHERE org.slug = :alias OR org.oid = :alias')->setParameter('alias', $orgAlias);
$org = $query->getOneOrNullResult();
if (!$org) throw new \Exception('Not Found', 404);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment