如何对单个实体使用XML映射,并保留通过注释映射的其余实体?

问题描述 投票:1回答:1

我正在基于Symfony 2.8向旧版应用程序添加新功能(hackzilla/Ticket-bundle,并且我需要扩展此捆绑包的基本实体,以便能够添加一些自定义字段。

在该应用程序中,所有实体都使用批注进行映射,但是基于此doc,要从Ticket-bundle扩展实体,我很可能需要使用XML映射。

是否有一种方法可以对单个/多个实体使用XML映射,但不能对所有实体使用XML映射?

这是我当前的学说配置。

doctrine:
    dbal:
        driver:   pdo_mysql
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true
        dql:
           datetime_functions:
               month: DoctrineExtensions\Query\Mysql\Month
               monthname: DoctrineExtensions\Query\Mysql\MonthName
               ifnull: DoctrineExtensions\Query\Mysql\IfNull
symfony symfony-2.8
1个回答
0
投票

是,您需要禁用doctrine.orm.auto_mapping,而是手动映射实体。它可能看起来像这样(您可以忽略其中一些选项,使用捆绑包时,请查看链接的文档以获取更简短的示例):

doctrine:
    orm:
        mappings:
            App:
                is_bundle: true
                type: annotation
                dir: '%kernel.project_dir%/src/AppBundle/Entity'
                prefix: 'AppBundle\Entity'
                alias: App
            Ticket:
                is_bundle: true
                type: xml
                dir: '%kernel.project_dir%/src/TicketBundle/Entity'
                prefix: 'TicketBundle\Entity'
                alias: Ticket

另请参见:https://symfony.com/doc/current/reference/configuration/doctrine.html#mapping-configuration

© www.soinside.com 2019 - 2024. All rights reserved.