0

The problem is that I have 2 + databases defined in Symfony. And when I update table schema with

php app/console dotrine:schema:update --force

it makes the tables in the default database. I'd like to specify which database the table belongs to. How could i do that?

I'm using yaml(yml) format for the entities, example:

Test\ExampleBundle\Entity\TestTable:
    type: entity
    table: test_table
    id:
        id:
            type: integer
            generator:
                strategy: AUTO
    fields:
        name:
            type: string
            length: 255
        sound:
            type: smallint
1

1 Answer 1

4

Take a deeper look at How to work with Multiple Entity Managers and Connections section of the documentation.

Doctrine offers you the ability to have multiple connections. You can easily add entity managers to bind your entities to different predefined connections according to the bundles they belong to.

According to the documentation, you can bind bundles to entity managers, but here is A trick on how to use two entity managers in the same bundle,

If you want to bind entities from one bundle to different entity managers you can add a "dir" attribute to define a path to a specific entities folder.

Example,

    entity_managers:
        default:
            connection:       default
            mappings:
                MyBundle:
                    dir:      Path/To/EntityFolder1
        myManager:
            connection:       myConnection
            mappings:
                MyBundle:
                    dir:      Path/To/EntityFolder2

You can then put your bundle entities into the right folders according to the connection they are bound to.

Sign up to request clarification or add additional context in comments.

7 Comments

I tried this, but the documents u linked me to are 1.2 version and I'm using 2.0 and this is not working.
How about if I have 2 different databases for 1 bundle? And it has to know what table belongs to what database.
Ah thanks, I updated my answer. I don't think you can use two entity managers in one bundle, otherwise you can have a separate bundles for your entities.
I updated my answer, just try the trick I added and let me know if it works fine for you? and if this approach can help you manage your entities?
So since I use 2 databases for the tables, can I somehow seperate the table definitions, so I can make it like that? I managed to get all of the tables to the other database, but now I have to seperate the table definitions for each database. Is there any predefined way to seperate them?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.