Skip to content

Loading…

DDC-1871: Create a relation between two Entities in different EntityManager #2534

Closed
doctrinebot opened this Issue · 2 comments

2 participants

@doctrinebot

Jira issue originally created by user tibec:

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;
@doctrinebot

Comment created by @beberlei:

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.

@doctrinebot

Issue was closed with resolution "Can't Fix"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.