core
core copied to clipboard
Symfony Uuid not working with search filter
API Platform version(s) affected: 2.6.5
Description
I Created two entities. One of them have ManyToOne relation with another. I used Symfony uuid as a type for id, exposed both of them to api plaform, I tried to filter them based on URI from another entity. Each time I get 0 results found. If I use ramsey uuid instead, everything works as expected
Additional Context
use Symfony\Component\Uid\Uuid;
use Symfony\Component\Uid\UuidV4;
#[ApiFilter(SearchFilter::class, properties: ['blog' => 'exact'])]
/**
* @var Uuid
* @ApiProperty(identifier=true)
* @ORM\Id
* @ORM\Column(name="id", type="uuid", unique=true)
*/
private $id;
public function __construct()
{
$this->id = UuidV4::v4();
}
public function getId(): Uuid
{
return $this->id;
}
Anyone was able to setup it correctly?
Hello,
There is a known bug on searchFilter with UUID. I provided a MR that was accepted on 2.6 but reverted on 2.7
You can use the current patch to make it work temporarily : https://gist.github.com/odoucet/4431492243d1a47bce55ee3d9957af67 And use cweagans/composer-patches to automatically patch APIP when you run composer install.
Maybe this new version works with both Symfony and Ramsey UUID.
This issue does still exist on 2.6.8. The patch by odoucet works.
you can use this bundle https://packagist.org/packages/webstack/api-platform-extensions-bundle
in doctrine.yaml
dbal:
mapping_types:
uuid_binary: binary
types:
uuid_binary: Ramsey\Uuid\Doctrine\UuidBinaryType
uuid_binary_ordered_time: Ramsey\Uuid\Doctrine\UuidBinaryType
Entity/xxx.php
#[ApiFilter(UuidFilter::class, properties: [
'uuid' => 'exact'
])]
search by
?uuid=88dfefe7-b1fb-4a51-9e32-144f9d625836
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I think UUIDs should be supported by default, not by using a bundle. What do you think?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Thanks @odoucet
I rebased your patch on Api Platform Core 3.1 and it work fine for me. Here is the link to the patch in case someone need it https://gist.github.com/tienvx/251bb458165e8442b7dd5fd58ce50bd9
The method how to use this patch is already mentioned in this comment https://github.com/api-platform/core/issues/4360#issuecomment-912386937