Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EntityRelationRule failing for every custom type even when type descriptors are registered #417

Open
janedbal opened this issue Jan 18, 2023 · 0 comments

Comments

@janedbal
Copy link
Contributor

Having following entity with custom type and descriptor:

enum FeeCategory: string {}

#[Entity]
class Fee
{

    #[Column(type: FeeCategoryType::NAME]
    private FeeCategory $feeCategory;

}

class FeeCategoryType extends StringType
{

    final public const NAME = 'fee_category';

    /**
     * @return class-string<BackedEnum<string>>
     */
    public function getEnumClass(): string
    {
        return FeeCategory::class;
    }

    public function getName(): string
    {
        return self::NAME;
    }

    /**
     * @param BackedEnum<string>|string|null $value
     * @return BackedEnum<string>|null
     */
    public function convertToPHPValue($value, AbstractPlatform $platform): ?BackedEnum
    {
        if ($value instanceof BackedEnum) {
            return $value;
        }

        $value = parent::convertToPHPValue($value, $platform);

        if ($value === null) {
            return null;
        }

        return static::getEnumClass()::from($value);
    }

    /**
     * @param BackedEnum<string>|string|null $value
     */
    public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string
    {
        if (!$value instanceof BackedEnum) {
            return $value;
        }

        return $value->value;
    }

    public function requiresSQLCommentHint(AbstractPlatform $platform): bool
    {
        return true;
    }

}

class FeeCategoryTypeDescriptor implements DoctrineTypeDescriptor
{

    public function getType(): string
    {
        return FeeCategoryType::class;
    }

    public function getWritableToPropertyType(): Type
    {
        return new ObjectType(FeeCategory::class);
    }

    public function getWritableToDatabaseType(): Type
    {
        return new StringType();
    }

    public function getDatabaseInternalType(): Type
    {
        return new StringType();
    }

}

Still produces error

Property Fee::$feeCategory type mapping mismatch: property can contain FeeCategory but database expects string.

I think this rule should utilize the knowledge from the descriptor.


Used version: 1.3.29, bleedingEdge enabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant