Generate entity using a particular connection

0

Consider the following configuration file:

config.yml

doctrine:
    dbal:
        default_connection: slqX45
        connections:
            slqX44:
                driver:   pdo_mysql
                host:     "%database_host%"
                port:     "%database_port%"
                dbname:   "%database_name%"
                user:     "%database_user%"
                password: "%database_password%"
                charset:  UTF8
            slqX45:
                driver:   pdo_mysql
                host:     "%database_host_co%"
                port:     "%database_port_co%"
                dbname:   "%database_name_co%"
                user:     "%database_user_co%"
                password: "%database_password_co%"
                charset:  UTF8

Notice that the connection marked as default is sqlX45 .

However I have some entities that have their respective tables in the A database and others in the B database, so the need to use 2 connections.

When you execute the following commands in the console, you must specify which connection to use and which entity, for example:

app/console doctrine:generate:entities --entidade="EntidadeA" --conexao="slqX44" 
app/console doctrine:schema:update --entidade="EntidadeA" --conexao="slqX44"

How to do this?

    
asked by anonymous 04.07.2016 / 14:24

1 answer

1

When you create Doctrine connection settings within a Symfony project, you can determine different entity managers for each connection. For each entity manager , it is possible to discriminate entities (and hence tables) to be managed.

Take a look at the Doctrine configuration .

So I think your configuration would look something like this:

doctrine:
    dbal:
        default_connection: slqX45
        connections:
            slqX44:
                driver:   pdo_mysql
                host:     "%database_host%"
                port:     "%database_port%"
                dbname:   "%database_name%"
                user:     "%database_user%"
                password: "%database_password%"
                charset:  UTF8
            slqX45:
                driver:   pdo_mysql
                host:     "%database_host_co%"
                port:     "%database_port_co%"
                dbname:   "%database_name_co%"
                user:     "%database_user_co%"
                password: "%database_password_co%"
                charset:  UTF8
    orm:
        entity_managers:
            em_sqlX44:
                connection: slqX44
                mappings: ~ # os mapeamentos que o EM em_sqlX44 gerenciará
            em_sqlX45:
                connection: slqX45
                mappings: ~ # os mapeamentos que o EM em_sqlX45 gerenciará

After that, just take a look at the arguments supported by each of the commands. In general, they accept that you specify in which entity manager that command will run - then, with which entities the command will work.

The argument that commands use is --entity-manager=(seu entity manager) .

    
06.07.2016 / 09:40