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

CustomType conversion is not working in QueryBuilder Where expression #11698

Open
wants to merge 2 commits into
base: 2.20.x
Choose a base branch
from

Conversation

dbannik
Copy link
Contributor

@dbannik dbannik commented Oct 25, 2024

related bug #9989

@dbannik
Copy link
Contributor Author

dbannik commented Oct 25, 2024

how i solve this problem for myself

final class FixSqlWalker extends SqlWalker
{
    public function walkPathExpression($pathExpr): string
    {
        $sql = parent::walkPathExpression($pathExpr);

        if ($pathExpr->type === PathExpression::TYPE_STATE_FIELD) {
            $fieldName    = $pathExpr->field;
            $dqlAlias     = $pathExpr->identificationVariable;
            $class        = $this->getMetadataForDqlAlias($dqlAlias);
            $fieldMapping = $class->fieldMappings[$fieldName] ?? [];

            if (isset($fieldMapping['requireSQLConversion'])) {
                $type = Type::getType($fieldMapping['type']);
                $sql  = $type->convertToPHPValueSQL($sql, $this->getConnection()->getDatabasePlatform());
            }
        }

        return $sql;
    }
}
class Kernel extends BaseKernel
{
    use MicroKernelTrait;

    #[Override]
    public function boot(): void
    {
        parent::boot();

        $this->container
            ->get('doctrine.orm.entity_manager')
            ->getConfiguration()
            ->setDefaultQueryHint(Query::HINT_CUSTOM_OUTPUT_WALKER, FixSqlWalker::class)
        ;
    }
}

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

Successfully merging this pull request may close these issues.

1 participant