2

I have two databases in my project.

First database named : global
Second database named : first_db

Global database has a table Car and Moto and the first_db database has tables Items , Bus and Ship.

Below the post you see the annotations of table Items.

 * @ORM\Table(name="Items")
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="type", type="string")
 * @ORM\DiscriminatorMap( {
 *      "car" = "Project\ItemBundle\EntityGlobal\Car",
 *      "moto" = "Project\ItemBundle\EntityGlobal\Moto",
 *      "bus" = "Bus",
 *      "ship" = "Ship",
 *  }
 * )

When I create query with DQL it doesn't understand that car and moto are in the other database. I have found a beta solution if entities Car and Moto set annotation with this method

* @ORM\Table(name="global.Moto")
* @ORM\Table(name="global.Car")

On update schema I don't have a problem, but it's not very safe. I know i can write native queries but I am not sure its the optimal way.

What is one better way to do this not using native queries?

nana
  • 4,426
  • 1
  • 34
  • 48

1 Answers1

0

In a basic setup from Symfony you are only using 1 database, which is defined in the parameters.yml. Using a second database is possible, but makes everything more complex

Using multiple databases (connections) can be setup like this: http://symfony.com/doc/current/cookbook/doctrine/multiple_entity_managers.html

But connecting different entities from different databases (connections) is not possible, see this answer: Using Relationships with Multiple Entity Managers

I suggest you strongly look at merging your tables into one database, to make your life a lot easier.

Community
  • 1
  • 1
Rein Baarsma
  • 1,466
  • 13
  • 22