I'm using MySQL and Doctrine 2 (with Symfony 3).
I want to set up a ManyToMany relationship between two entities which are in two separate databases.
I rode that Doctrine doesn't handle this, at least not in an native way. To perform that anyway, I'm using the schema
attribute on my tables definitions.
Let's say I have those 2 entities :
/**
* @ORM\Table(schema="bdd2", name="site")
*/
class Site {}
and
/**
* @ORM\Table(name="user")
*/
class User {}
I do not use the schema
attribute on the User
entity because my entity manager is configured to use its database, so it's useless. I set up the relationship in User
one this way:
/**
* @ORM\ManyToMany(targetEntity="[...]")
*/
private $sites;
Quite simple. In the code side, it works, the relation is effective.
In the database side, it's not ok, because the user_site
table generated by doctrine has only one foreign key (for the user): it doesn't contain the foreign key to the second database. The field exists, has an index, but not foreign key.
If I add the foreign key by myself, each time I do a php bin/console doctrine:schema:update --dump-sql
Doctrine want to remove it.
The question is: How can I make doctrine create this second foreign key? or if it's not possible, How can I make doctrine ignore the one I created myself ?