gpt4 book ai didi

php - 在 Symfony2 中使用同一包中的两个实体管理器

转载 作者:行者123 更新时间:2023-12-02 23:40:34 25 4
gpt4 key购买 nike

我正在尝试与同一个 bundle 的两个实体管理器合作。我的配置是这样的:

orm:

default_entity_manager: default
entity_managers:
electra:
connection: electra
mappings:
XXDemoBundle: ~
default:
connection: default
mappings:
XXDemoBundle: ~

有什么方法可以告诉哪些实体属于哪个实体管理器?如果我想使用不属于默认实体管理器的表,它现在会崩溃。

  • 更新

这是我的连接配置:

doctrine:
dbal:
default_connection: default
connections:
default:
dbname: old_project
user: root
password: 123123
host: 1.1.1.1
port: 1
electra:
dbname: electra
user: root
password: 123123
host: 2.2.2.2
port: 2

orm:
default_entity_manager: electra
entity_managers:
electra:
connection: electra
mappings:
XXDemoBundle: ~


default:
connection: default
mappings:
XXDemoBundle: ~

最佳答案

要在同一包中使用多个实体管理器,您必须为每个实体管理器配置映射选项。

http://symfony.com/doc/current/reference/configuration/doctrine.html

配置文件示例

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" 

You can now use console for managing your db with the --em parameter

Ex : update database for shop entitymanager

php app/console doctrine:schema:update --em=shop

从 Your\Bundle\Entity\SecondDb 读取映射信息

例如:更新默认实体管理器的数据库

php app/console doctrine:schema:update   

从 Your\Bundle\Entity\FirstDb 读取映射信息

关于php - 在 Symfony2 中使用同一包中的两个实体管理器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9311485/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com