diff --git a/Event/Subscriber/DoctrineORMSubscriber.php b/Event/Subscriber/DoctrineORMSubscriber.php index 3db9776..ffaecb1 100644 --- a/Event/Subscriber/DoctrineORMSubscriber.php +++ b/Event/Subscriber/DoctrineORMSubscriber.php @@ -108,7 +108,7 @@ public function filterEntity(GetFilterConditionEvent $event) $expr->eq($filterField, ':'.$paramName), array($paramName => array( $this->getEntityIdentifier($values['value'], $queryBuilder->getEntityManager()), - Types::INTEGER + $this->getEntityIdentifierType($values['value'], $queryBuilder->getEntityManager()), )) ); } @@ -137,4 +137,23 @@ protected function getEntityIdentifier($value, EntityManagerInterface $em) return array_shift($identifierValues); } + + /** + * @param object $value + * @return string + * @throws \RuntimeException + */ + protected function getEntityIdentifierType($value, EntityManagerInterface $em) + { + $class = get_class($value); + $metadata = $em->getClassMetadata($class); + + $identifierType = $metadata->getIdentifierFieldNames($value); + + if (empty($identifierType)) { + throw new \RuntimeException(sprintf('Can\'t get identifier value for class "%s".', $class)); + } + + return $metadata->getTypeOfField(array_shift($identifierType)); + } }