symfony2admingenerator / AdmingeneratorGeneratorBundle

(old-legacy) Admingenerator for Symfony2, parse generator.yml files to build classes
http://symfony2admingenerator.org/
MIT License
360 stars 125 forks source link

Set custom EntityManager in generator.yml #747

Closed mirza99 closed 10 years ago

mirza99 commented 10 years ago

Being able to manage more then one database. With a parameter like : manager: default # or a function (maybe of a service) returning the connection name.

When none/null set, the default will be taken.

bobvandevijver commented 10 years ago

The Doctrine ORM version is already capable of using multiple managers, see for instance here.

All methods (should) use the ->getManagerForClass method to determine the correct manager, so multiple managers should work automatically.

mirza99 commented 10 years ago

It works for classes but if you want to set a manager on your own logic ? For my needs, I have to set a different database for each of my customers (not Symfony user) so I thought to create a service that returns the connexion name depending on the user's company. If the feature is accepted, I can work on it this week to add it.

bobvandevijver commented 10 years ago

Better idea might be to extend the Doctrine Registry object: That way you can rewrite the getManagerForClass and getManager methods to match your needs and use it everywhere without the need to extend this bundle. Also, you can use it directly everywhere in the code.

Actually: the function you describe was available earlier, see #471. This was later changed to the current implementation in #639 as the getManager implementation seemed to be a little bit unstable.

mirza99 commented 10 years ago

Ok, so I have just to activate it in config.yml with default_entity_manager: /path/to/customRegistry ? When is the method getManagerForClass called ? I think that I don't need this method. I'll just override the getManager method

bobvandevijver commented 10 years ago

Check the code of Doctrine\Common\Persistence\ManagerRegistry\AbstractManagerRegistry. The getManagerForClass is always called by the Admingenerator, so you would need to adjust that.

However, I still don't get the point of multiple, different databases for the same entities in the same application. Maybe the better solution is to just split the environments for every customer.

mirza99 commented 10 years ago

Thanks !

I know, it sounds weird but that's the decision of the project manager. It's about performance. We'll have about 100 customers and each customer have about 15k contacts or more. And we will have to send them mails, generate pdf files, xls files... I'm thinking too that it's not so much 1,5M rows...