cycle/orm

๐Ÿ› ManyToMany id typecast gets wrong id

gam6itko opened this issue ยท 1 comments

No duplicates ๐Ÿฅฒ.

  • I have searched for a similar issue in our bug tracker and didn't find any solutions.

What happened?

After update to 2.3.3 I've got ManyToMany Relation bug. It pass to my custom UuidTypecaster id of Post but not File.

The problem appeared after this changes c7edd6b#diff-e299fc705879bf607db737052f5877933b57a8f09771af24ccad1ff70ea3ad9a

#[Cycle\Entity(table: 'post')]
class Post {
    /**
     * @var File[]
     */
    #[Cycle\Relation\ManyToMany(target: File::class, though: PostScreenshot::class, throughInnerKey: 'post_id')]
    private array $screenshots = [];
}


#[Cycle\Entity(table: 'post_screenshot')]
class PostScreenshot
{
    #[Cycle\Column(type: 'primary', unsigned: true)]
    private ?int $id = null;
}


#[Cycle\Entity(
    table: 'file',
    typecast: [
        \Cycle\ORM\Parser\Typecast::class,
        UuidTypecast::class,
    ]
)]
class File
{
    #[Cycle\Column(type: 'string(36)', primary: true, typecast: 'uuid')]
    private UuidInterface $id;
}


final class UuidTypecast extends AbstractTypecast
{
    protected function getType(): string
    {
        return 'uuid';
    }

    protected function fromDbValue(mixed $value): mixed
    {
        return Uuid::fromString($value);
    }

    protected function toDbValue(mixed $value): mixed
    {
        assert($value instanceof UuidInterface); // bug here
        return $value->toString();
    }
}

Version

ORM 2.3.3
PHP 8.1

Will be fixed in ORM 2.3.4 or 2.4.0