1

I have 2 doctrine entities:

class User extends BaseUser
{
    /**
     * @var ArrayCollection
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\Account", mappedBy="user")
     */
    protected $accounts;

and:

class Account
{
    /**
     * @var \UserBundle\Entity\User
     * @ORM\ManyToOne(targetEntity="\UserBundle\Entity\User", inversedBy="accounts")
     * @ORM\JoinColumn(name="a_person_obj_id", referencedColumnName="obj_id")
     */
    protected $user;

The problem is that the data for Account entity storeted in different database that entity User.

When I getting User entity:

$userRepository = $this->getDoctrine()->getRepository('UserBundle:User', 'db1');
$user = $userRepository->find($user);

and start iterating by $user->getAccounts() I getting exception:

SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "account" does not exist

and this absolutely correct, because Account stored in "db2" and I need to user different entity manager for this data.

What's the best practices to make relation between many databases for entity?

P.S. I used to postgreSQL database.

  • Simply said: Doctrine is unable to handle relationships between multiple databases. Have a look at http://stackoverflow.com/questions/11463517/using-relationships-with-multiple-entity-managers for an alternative approach. – bspellmeyer Jun 16 '15 at 12:30

0 Answers0