zenstruck / foundry

A model factory library for creating expressive, auto-completable, on-demand dev/test fixtures with Symfony and Doctrine.
https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html
MIT License
670 stars 75 forks source link

Allow specifying connection used by foundry #700

Open BackEndTea opened 1 month ago

BackEndTea commented 1 month ago

Currently its not possible to specify the connection that is used by foundry for the inserts. This is a problem for me as the project i'm working on uses multiple connections, and the default connection may not have insert rights for the entity i want to persist.

In the flow of the application the correct connection would be used for inserts, but this is not possible to configure for foundry.

Right now we can already specify the connection/entity manger to be used for resets: https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html#database-reset

However we can't specify the connection that does the inserts. I would like something like

zenstruck_foundry:
   default_entity_manager: my_manager # defaults to doctrine.orm.default_entity_manager
nikophil commented 1 month ago

Hi @BackEndTea

I'm not very familiar with working with multiple entity managers in the same app.

Correct me if I'm wrong: when working with several EM, can you have two EM which "manages" the same entity? In your case one is readonly (the default one), and the other one has write access?

I'd be OK for such a modification, but I'm trying to figure out if a default_entity_manager configuration is the best option :thinking: what if we have 2 databases, with each of them 2 EM, this would not work... Not sure if this is a common setup (I've never seen this in the wild), but I wouldn't want to be stuck if some day someone comes with such a problem