我的目标是让两个不同的文档管理器连接到共享相同数据库模型的不同数据库。
我已经对我的数据库模型进行了重大更改,我想编写一个自定义迁移脚本,该脚本从旧模型中检索对象并读取其值,然后使用旧对象的信息在新模式上创建一个新对象。
我在这里找到了一个相关的 stackoverflow 问题: Working with two entity manager in the same bundle in Symfony2
但是,此解决方案建议为每个数据库使用不同的前缀,并将数据模型的类存储在不同的文件夹中:
doctrine:
dbal:
default_connection: default
connections:
default:
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
charset: UTF8
second:
driver: %database_sqlite_driver%
host: ~
port: ~
dbname: %database_sqlite_shop_name%
path: %database_sqlite_shop_name%
user: ~
password: ~
charset: UTF8
orm:
auto_generate_proxy_classes: %kernel.debug%
default_entity_manager: default
entity_managers:
default:
connection: default
mappings:
YourBundle:
# you must specify the type
type: "annotation"
# The directory for entity (relative to bundle path)
dir: "Entity/FirstDb"
#the prefix
prefix: "Your\Bundle\Entity\FirstDb"
shop:
connection: second
mappings:
YourBundle:
type: "annotation"
#here the second path where entity for the connection stand
dir: "Entity/SecondDb"
#the prefix
prefix: "Your\Bundle\Entity\SecondDb"
我真的很想有两个不同的文档管理器对象,它们在同一个文件夹中共享相同的模型,但连接到不同的数据库。这可能吗?