Basically, i have a branch of code that connects to three different entity managers (and subsequently, three different MySQL databases). Unfortunately, two of the databases have tables that are named he same thing, so i cant have all the entities in the same directory, and for structure, id like to avoid that anyways.
So, my question is... How would i set it up so i can have a single entity bundle, with sub-directories under Entity\
and Resources\config\doctrine\
e.g.
Acme\EntityBundle\Entity\DB1\Test.php
Acme\EntityBundle\Entity\DB1\Acme.php
Acme\EntityBundle\Entity\DB2\Test.php
Acme\EntityBundle\Entity\DB2\Foo.php
Acme\EntityBundle\Entity\DB3\Bar.php
and the same idea for Resources\config\doctrine\
The configs are very vague on what to do here...
You only need to rename your doctrine configurations files.
So for example:
Bundle/Entity/DB1/User.php
Bundle/Entity/DB2/User.php
results in the respective config files (.yml in this case, change as you please)
Bundle/Resources/config/doctrine/DB1.User.orm.yml
Bundle/Resources/config/doctrine/DB2.User.orm.yml
If you just need the bundle to store entities, I'd rather suggest to store them outside. This way you'd decouple them from the framework.
In both cases configuration is similar. Reference is accessible in the official docs.
Here's an example:
#app/config/config.yml
doctrine:
orm:
auto_generate_proxy_classes: %kernel.debug%
auto_mapping: true
mappings:
AcmeDB1:
type: xml
is_bundle: false
dir: %kernel.root_dir%/../src/Acme/Entity/DB1/config
prefix: Acme\Entity\DB1
alias: AcmeDB1
AcmeDB2:
type: xml
is_bundle: false
dir: %kernel.root_dir%/../src/Acme/Entity/DB2/config
prefix: Acme\Entity\DB2
alias: AcmeDB2
Few notes:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With