Skip to content

Instantly share code, notes, and snippets.

@roolo
Created November 7, 2011 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roolo/1345249 to your computer and use it in GitHub Desktop.
Save roolo/1345249 to your computer and use it in GitHub Desktop.
Coalesce in query builder - symfony2
<?php
$queryBuilder->addSelect(
sprintf(
'COALESCE(%s.weight+%s.weight, %s.weight) AS weightBefore',
$object1->getEntityAlias(),
$object2->getEntityAlias(),
$object1->getEntityAlias()
)
);
<?php
$queryBuilder->andWhere(
sprintf(
'coalesce(%s.weight+%s.weight, %s.weight) = %s',
$object1->getEntityAlias(),
$object2->getEntityAlias(),
$object1->getEntityAlias(),
$valueFromForm
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment