简体   繁体   English

Symfony2 / Doctrine2 - 将实体关联到某个连接

[英]Symfony2 / Doctrine2 - Associating entities to certain connection

I have two MySQL connections set in my Symfony config.yml: 我在Symfony config.yml中设置了两个MySQL连接:

doctrine:
    dbal:
        default_connection: default
        connections:
            default: __VARIABLES
            dealer: __VARIABLES

I know I can retrieve objects from certain connection by: $this->get('doctrine')->getEntityManager('dealer'); 我知道我可以通过以下方式从某些连接中检索对象: $this->get('doctrine')->getEntityManager('dealer');

My question is - is there a way to set connection to certain entity, so the doctrine:schema:update syncing is done only in the scope of the set connection? 我的问题是 - 有没有办法设置与某个实体的连接,所以doctrine:schema:update syncing只在set连接的范围内完成?

Yes - you can specify in entity manager section entity manager's responsibility. 是 - 您可以在实体管理器部分中指定实体经理的职责。 You can use "dir" option for this purpose. 您可以使用“dir”选项来实现此目的。 You have to disable auto_mapping options and tell Doctrine which entities are related to which entity manager. 您必须禁用auto_mapping选项并告诉Doctrine哪些实体与哪个实体管理器相关。 For example: 例如:

doctrine:
   dbal:
       (...)

   orm:
       auto_generate_proxy_classes: %kernel.debug%        
       default_entity_manager:   default
       entity_managers:
           default:
               connection:       default
               mappings:                    
                   CompanySomeBundle:
                       dir: Entity/BaseEntity/

            secondem:
                connection:      second_connection
                mappings:                 
                    CompanySomeBundle:
                       dir: Entity/AdditionalEntity/

In that every entity in BaseEntity dir belongs to "default" em, and these entities from AdditionalEntity dir belong to "secondem" entity manager. 因为BaseEntity目录中的每个实体都属于“默认”em,而来自AdditionalEntity目录的这些实体属于“secondem”实体管理器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM