Skip to content

Instantly share code, notes, and snippets.

@johnnypeck
Created January 17, 2014 03:11
Show Gist options
  • Save johnnypeck/8467782 to your computer and use it in GitHub Desktop.
Save johnnypeck/8467782 to your computer and use it in GitHub Desktop.
If I use the randProps variable as the identifiers Doctrine ORM somehow still returns records where the managedStatus is not 20.
if ($comparison->getIds()) {
$identifiers = $comparison->getIds();
$random = false;
} else {
// we go random
$random = true;
/* @var $conn \Doctrine\DBAL\Connection */
$conn = $this->get('database_connection');
$stmt = $conn->executeQuery('SELECT id, managedStatus FROM property p WHERE managedStatus = ?', array(20));
$props = $stmt->fetchAll();
$randProps = array_rand($props, 3);
$identifiers = $randProps;
}
$hydrationMode = Query::HYDRATE_OBJECT;
$em = $this->getDoctrine()->getManager();
$repo = $em->getRepository('Attache\MainBundle\Entity\Property');
/* @var $qb \Doctrine\ORM\QueryBuilder */
$qb = $repo->createQueryBuilder('p');
$qb
->where($qb->expr()->in('p.id', ':values'))
->setParameter('values', $identifiers)
;
$properties = $qb->getQuery()->setHydrationMode($hydrationMode)->execute();
@johnnypeck
Copy link
Author

When I dump the identifiers returned by the DBAL there are no records without a managedStatus of 20. Once it gets to the last query it ends up returning records that have a managedStatus of 20. Why? I'm missing something for sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment