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

Multiple ObjectManagers with doctrine #90

Open
vgeyer opened this issue Mar 14, 2018 · 3 comments
Open

Multiple ObjectManagers with doctrine #90

vgeyer opened this issue Mar 14, 2018 · 3 comments
Labels

Comments

@vgeyer
Copy link

vgeyer commented Mar 14, 2018

Hi,
i think i found a conceptional bug with the Service Definition of the object manager persister:

        <service id="fidry_alice_data_fixtures.persistence.persister.doctrine.object_manager_persister"
                 class="Fidry\AliceDataFixtures\Bridge\Doctrine\Persister\ObjectManagerPersister"
                 lazy="true">
            <argument type="service" id="doctrine.orm.entity_manager" />
        </service>

Having this service definition a persist(object) in the Fidry\AliceDataFixtures\Loader\PersisterLoader::load causes the object to be not persistet to the database if it is not in the entity namespace of the default object manager. This is because doctrine.orm.entity_manager is an alias for the default connection.

One solution would be to add all existing entity managers to the \Fidry\AliceDataFixtures\Bridge\Doctrine\Persister\ObjectManagerPersister and determine by the getPersistableClasses method which object manager is used for persisting. The only problem with this solution is that an entity can be used in multiple managers. But this may be one of the more rare cases i guess...

@theofidry
Copy link
Owner

Hello.

If you can find a way generic enough for persisting the entities with multiple object managers I'm happy to merge that solution.

Meanwhile, an easy way to fix it is to override the object manager persister service definition to inject the desired entity manager.

@jdlabails
Copy link

Hello,

When do you think it would be possible to play with several entity managers ?
Can you explain your temporary solution to fix it in our code.

Thank you

@theofidry
Copy link
Owner

theofidry commented Jan 8, 2021

@jdlabails as stated in my previous comment, I'm still unsure on how it should be implemented. As for the workaround, the library currently relies on an object manager persister service: you can create your own instead to use multiple managers instead of just the default one

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

Successfully merging a pull request may close this issue.

3 participants