diff --git a/src/Doctrine/Odm/Filter/SearchFilter.php b/src/Doctrine/Odm/Filter/SearchFilter.php index 63870618639..843dbe2caac 100644 --- a/src/Doctrine/Odm/Filter/SearchFilter.php +++ b/src/Doctrine/Odm/Filter/SearchFilter.php @@ -31,6 +31,8 @@ use Symfony\Component\PropertyAccess\PropertyAccess; use Symfony\Component\PropertyAccess\PropertyAccessorInterface; use Symfony\Component\Serializer\NameConverter\NameConverterInterface; +use Symfony\Component\Uid\Ulid; +use Symfony\Component\Uid\Uuid; /** * The search filter allows to filter a collection by given properties. @@ -221,7 +223,14 @@ protected function filterProperty(string $property, $value, Builder $aggregation return; } - $values = array_map($this->getIdFromValue(...), $values); + $values = array_map(function ($value) { + $id = $this->getIdFromValue($value); + if ($id instanceof Uuid || $id instanceof Ulid) { + return $id->toBinary(); + } + + return $id; + }, $values); $associationResourceClass = $metadata->getAssociationTargetClass($field); $associationFieldIdentifier = $metadata->getIdentifierFieldNames()[0]; diff --git a/src/Doctrine/Orm/Filter/SearchFilter.php b/src/Doctrine/Orm/Filter/SearchFilter.php index 4133f33ad91..9b9aacb5a81 100644 --- a/src/Doctrine/Orm/Filter/SearchFilter.php +++ b/src/Doctrine/Orm/Filter/SearchFilter.php @@ -31,6 +31,8 @@ use Symfony\Component\PropertyAccess\PropertyAccess; use Symfony\Component\PropertyAccess\PropertyAccessorInterface; use Symfony\Component\Serializer\NameConverter\NameConverterInterface; +use Symfony\Component\Uid\Ulid; +use Symfony\Component\Uid\Uuid; /** * The search filter allows to filter a collection by given properties. @@ -196,7 +198,6 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB } $metadata = $this->getNestedMetadata($resourceClass, $associations); - if ($metadata->hasField($field)) { if ('id' === $field) { $values = array_map($this->getIdFromValue(...), $values); @@ -255,6 +256,7 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB $expected = \count($values); $values = array_filter($values, static fn ($value) => null !== $value); + $values = array_map(static fn ($value) => $value instanceof Uuid || $value instanceof Ulid ? $value->toBinary() : $value, $values); if ($expected > \count($values)) { /* * Shouldn't this actually fail harder? @@ -272,7 +274,6 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB $associationAlias = QueryBuilderHelper::addJoinOnce($queryBuilder, $queryNameGenerator, $alias, $associationField); $associationField = $associationFieldIdentifier; } - $this->addWhereByStrategy($strategy, $queryBuilder, $queryNameGenerator, $associationAlias, $associationField, $values, $caseSensitive); } diff --git a/tests/Fixtures/TestBundle/Document/JsonSchemaContextDummy.php b/tests/Fixtures/TestBundle/Document/JsonSchemaContextDummy.php index 020f06b1145..085c49d5524 100644 --- a/tests/Fixtures/TestBundle/Document/JsonSchemaContextDummy.php +++ b/tests/Fixtures/TestBundle/Document/JsonSchemaContextDummy.php @@ -30,7 +30,6 @@ class JsonSchemaContextDummy * @var int The id * * @ApiProperty(identifier=true) - * * @ODM\Id(strategy="INCREMENT", type="int") */ private $id;