用Doctrine生成实体到单独的命名空间 [英] Generate Entities with Doctrine into separate namespace

查看:284
本文介绍了用Doctrine生成实体到单独的命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在以下文档中:

  • http://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html

这些是命令

php app/console doctrine:mapping:convert xml ./src/Acme/BlogBundle/Resources/config/doctrine/metadata/orm --from-database --force
php app/console doctrine:mapping:import AcmeBlogBundle annotation
php app/console doctrine:generate:entities AcmeBlogBundle

我在

Acme/BlogBundle/AcmeBlogBundle/Entity

但是我想知道如何将Entities添加到自己的命名空间中,如下所示。

But I wanted to know how I could add the Entities into their own namespace like this

Acme/BlogBundle/AcmeBlogBundle/Entity/Foo
Acme/BlogBundle/AcmeBlogBundle/Entity/Bar

这是所以我可以保留Foo和Bar数据库的实体分离。

This is so I could keep the Entities for Foo and Bar Databases separated.

更新:

或者应该是结构化像这样:

Or should it be structured like this:

Acme/BlogBundle/AcmeBlogBundle/Foo/Entity
Acme/BlogBundle/AcmeBlogBundle/Bar/Entity

想法?

推荐答案

如果您查看如何使用多个实体管理器和连接您将注意到,您可以将捆绑实体绑定到一个或多个实体管理器。每一个都与特定的数据库连接相关。

If you take a look at How to work with Multiple Entity Managers and Connections section of the documentation, you'll notice that you can bind your bundle entities to one or many entity managers. Each one of them related to a specific database connection.

如果我已经定义了两个数据库连接(first_connection和second_connection),我可以添加两个实体管理器跟随,

If for example I've defined two database connections (first_connection and second_connection), I can than add two entity managers as follow,

entity_managers:
    first_manager:
        connection:       first_connection
        mappings:
            MyBundle:
                dir:      Path/To/EntityFolder/Foo/
    second_manager:
        connection:       second_connection
        mappings:
            MyBundle:
                dir:      Path/To/EntityFolder/Bar/

然后可以在两个第一步中指定正确的实体管理器的实体生成过程

You can then specify the right Entity Manager to use during the two first steps of the entity generation process,

php app/console doctrine:mapping:convert xml ./src/Acme/BlogBundle/Resources/config/doctrine/metadata/orm --from-database --force --em=first_manager --filter=MyTable

注意: strong> - 过滤器选项用于允许您单独生成您的实体。

Note: The --filter option is used to allow you generate your entities individually.

php app/console doctrine:mapping:import AcmeBlogBundle annotation --em=first_manager --filter=MyTable

php app/console doctrine:generate:entities AcmeBlogBundle

然后根据绑定的连接将您的实体放入正确的文件夹。

Your entities are then put into the right folders according to the connection the were bound to.

这篇关于用Doctrine生成实体到单独的命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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