core icon indicating copy to clipboard operation
core copied to clipboard

Symfony Uuid not working with search filter

Open syntaxgirl opened this issue 2 years ago • 3 comments

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?

syntaxgirl avatar Jul 18 '21 22:07 syntaxgirl

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.

odoucet avatar Sep 03 '21 09:09 odoucet

This issue does still exist on 2.6.8. The patch by odoucet works.

Cruiser13 avatar May 13 '22 15:05 Cruiser13

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

yunmoxue avatar Jun 12 '22 07:06 yunmoxue

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.

stale[bot] avatar Nov 04 '22 21:11 stale[bot]

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.

stale[bot] avatar Jan 04 '23 01:01 stale[bot]

I think UUIDs should be supported by default, not by using a bundle. What do you think?

Cruiser13 avatar Jan 04 '23 08:01 Cruiser13

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.

stale[bot] avatar Mar 05 '23 08:03 stale[bot]

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

tienvx avatar Apr 27 '23 13:04 tienvx