Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2: Creating entity table conditionally

I have a bundle with entity defined in it. I want to be able to configure this bundle in such a way, that this entity will or won't be relevant. So if bundle is configured properly entity table shouldn't be created with app/console doctrine:schema:update etc, or should be - it should depend on configuration.

How to conditionally "disable" entity so its table won't be created by app/console doctrine:schema:update?

like image 507
Łukasz Zaroda Avatar asked Oct 30 '22 08:10

Łukasz Zaroda


1 Answers

Your scenario requires you to disable the auto_mapping, but it seems to be set to false by default. http://symfony.com/doc/current/reference/configuration/doctrine.html

Next thing to do is make sure the build function of your bundle conditionally adds the wanted DoctrineOrmMappingPass as also is explained here: https://stackoverflow.com/a/26975083/1794894

As you can see in the source, build only is executed once the cache is empty so this is the place where you can do this. You can also take a look at how to add compiler passes there.

like image 198
Rvanlaak Avatar answered Nov 18 '22 22:11

Rvanlaak