Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1871

Create a relation between two Entities in different EntityManager

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Blocker Blocker
    • Resolution: Can't Fix
    • Affects Version/s: Git Master
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      Symfony2 with Doctrine2 using MySQL

      Description

      Hello,

      I'm working on a Symfony based CMS for a game server. The game server use two databases (the `auth` database and `characters` database) and i've created a new one for the CMS named `site`.

      Currently my News entity must have a relation with the Account entity but the News entity come from the Site EntityManager (who manage the `site` database) and the Account entity come from the Auth EntityManager (who manage the `auth` database).

      So, when I prompt the command "php app/console doctrine:schema:update --em="site" --force" I got the error "Class Eluna\MemberBundle\Entity\Account is not a valid entity or mapped super class." But if I join an entity who is in the same EntityManager it work perfectly.

      My code :

          /**
           * @var object $author
           *
           * @ORM\ManyToOne(targetEntity="Eluna\MemberBundle\Entity\Account")
           * @ORM\JoinColumn(name="author", referencedColumnName="id")
           */
          private $author;
      

        Activity

        Hide
        Benjamin Eberlei added a comment -

        Unless the entities are in the same database server (MySQL) but just in different databses you can use the syntax "database.table" in the @Table. Otherwise there is no nice solution, you have to save the foreign key manually in an integer column and maybe use an event listener to fetch a proxy of the related object. But that has to be coded manually.

        Show
        Benjamin Eberlei added a comment - Unless the entities are in the same database server (MySQL) but just in different databses you can use the syntax "database.table" in the @Table. Otherwise there is no nice solution, you have to save the foreign key manually in an integer column and maybe use an event listener to fetch a proxy of the related object. But that has to be coded manually.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Tibec
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: