FOSUserBundle with multiple entity managers - Symf

2019-08-04 10:40发布

问题:

I've been using the FOSUserBundle and the FOSOAuthBundle without issue in a project for a while now, but I've recently added another DB connection and another entity manager and, as a result, can no longer rely on auto_mapping.

I've added mapping for both of the bundles to one of the entity managers and everything seemed to be working OK.

However I've found an issue with the User no longer generating the correct schema when running app/console doctrine:schema:create, suggesting a mapping issue. It's worth noting that the client from FOSOAuthBundle is mapping OK.

It looks to me that the mapping in the FOSUserBundle is being ignored and I'm not sure what I'm doing wrong.

Entity Manager set up:

orm:
    default_entity_manager: default
    auto_generate_proxy_classes: %kernel.debug%

    entity_managers:
        other:
            connection: other
            mappings:
                SteveMainBundle: ~
        default:
            connection: default
            mappings:
                SteveMainBundle: ~
                SteveWebBundle: ~
                FOSUserBundle: ~
                FOSOAuthServerBundle: ~

fos_user set up:

fos_user:
    db_driver: orm
    firewall_name: main
    user_class: Steve\MainBundle\Entity\User

Any ideas?

回答1:

See this question for a possible solution.

you can specify a specific entity manager to be used with the command by adding em="entitymanager_name".

app/console doctrine:schema:create --dump-sql em="other"


回答2:

We solved this by upgrading the FOSUserBundle to the latest release (2.0). Not really sure what happened in this case, if it was a bug in the version we were on or not. Shall post here if I find out any more.



回答3:

You can set a custom entity manager by

model_manager_name

option. Look into documentation