在不同的数据库上使用Doctrine 2实体 [英] Using Doctrine 2 Entity with different databases

查看:87
本文介绍了在不同的数据库上使用Doctrine 2实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Symfony2浏览器游戏中,我有一个使用Doctrine 2 ORM的用户实体。该游戏有两个实例,经典和速度,这两个实例主要彼此独立,并且都使用自己的数据库(结构相同)。唯一的问题是用户可以连接其帐户,因此应显示所连接帐户的一些基本用户信息。为此,我有一个classic_id和speed_id作为连接到另一个用户实体的属性。但这将是一个跨数据库联接,据我所知在Doctrine 2中是不可能的。我还发现可以有多个具有各自连接的实体管理器,但我认为它们只能应用于完整的捆绑软件,对吗?

In my Symfony2 browsergame I have an user entity using the Doctrine 2 ORM. The game has two instances, classic and speed, which are mainly independent from each other and are using both its own databases (same structure). The only problem is that users are able to connect their accounts, so some basic user informations of the connected account shall be shown. For that I have a classic_id and speed_id as properties which connect to another user entity. But that would be a a cross database join which is not possible in Doctrine 2 as far as I found out. I also found that it is possible to have multiple entity managers with their own connections, but I think they can only be applied to complete bundles, right?

所以在这里我需要解决该问题的方法,最简单的方法是什么?

So here I need some workaround for that problem, what is the easiest way to do that?

推荐答案

实际上,有可能进行跨数据库联接,

Actually there is possibility to do cross db joins, but it's rather trick than a feature and I do not recommend use it.

要将实体与不同实体管理器之间的捆绑包分开,可以使用 dir属性,该属性指向受管实体。例如:

To separate entities from one bundle between different entity managers you can use "dir" attribute which points to managed entities. For example:

doctrine:
    orm:
        default_entity_manager:   default
        entity_managers:
            default:
                connection:       default
                mappings:
                    AppBundle:
                        dir:      Path/To/EntityFolder1
            anotherone:
                connection:       anotherconnection
                mappings:
                    AppBundle:
                        dir:      Path/To/EntityFolder2

有也是记录不完整的前缀选项,但我还没有弄清楚它是什么(您可以自己尝试:))

There is also poor documented "prefix" option, but I didn't figure out what it is yet (you can experiment by yourself:))

问候!

这篇关于在不同的数据库上使用Doctrine 2实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆