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

Does not use custom TypedFieldMapper #557

Closed
michnovka opened this issue Oct 16, 2024 · 4 comments
Closed

Does not use custom TypedFieldMapper #557

michnovka opened this issue Oct 16, 2024 · 4 comments

Comments

@michnovka
Copy link

I have an issue with migrations, as they do not use my custom TypedFieldMapper.

I configure it like this in services.yaml:

services:
    App\ORM\TypedFieldMapper\MyTypedFieldMapper:

    doctrine.orm.configuration:
        class: Doctrine\ORM\Configuration
        calls:
            - setTypedFieldMapper: [ '@App\ORM\TypedFieldMapper\MyTypedFieldMapper' ]

And this works fine when running the app. But when doing doctrine:migrations:diff then this is not used and instead Doctrine\ORM\Mapping\DefaultTypedFieldMapper is used.

How do I tell migration bundle to use my custom typed field mapper?

@michnovka
Copy link
Author

I found that Doctrine\Orm\Configuration::setTypedFieldMapper() is called twice. First, correctly with the data configured in services.yaml. But then once again but with the DefaultTypedFieldMapper.

@michnovka
Copy link
Author

Hmm, I think maybe this is not related to migrations at all. I checked var/cache/dev/Container50KivA3/App_KernelDevDebugContainer.php and I see it has function getDoctrine_Orm_DefaultEntityManagerService function.

Here, I have on top:

        $a->setTypedFieldMapper(new \App\ORM\TypedFieldMapper\MyTypedFieldMapper());
        $a->setEntityNamespaces(['App' => 'App\\Entity']);

and then few lines below it

        $a->setTypedFieldMapper(new \Doctrine\ORM\Mapping\DefaultTypedFieldMapper());

So, the issue is that my setTypedFieldMapper call from services.yaml is called before the one that overrides it.

Any ideas how to fix this please?

@michnovka
Copy link
Author

Ok, so I guess this has to be implemented: doctrine/DoctrineBundle#1696

I will close this issue, as it is unrelated to migrations, but please, anybody knows how I can call

    doctrine.orm.configuration:
        class: Doctrine\ORM\Configuration
        calls:
            - WHATEVER

AFTER all the default ones are called?

@michnovka
Copy link
Author

As of doctrine/DoctrineBundle#1802 we have a way to specify any service as TypedFieldMapper under doctrine.orm.typed_field_mapper

This is documented at https://symfony.com/bundles/DoctrineBundle/2.13.x/configuration.html

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