【问题标题】:How to use XML mapping for single entity and keep the rest of entities mapped by Annotations?如何为单个实体使用 XML 映射并保持由注释映射的其余实体?
【发布时间】:2019-10-08 10:33:23
【问题描述】:

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

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

有没有办法为单个/多个实体使用 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】:

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

    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

    【讨论】:

      猜你喜欢
      • 2015-08-16
      • 1970-01-01
      • 2010-10-06
      • 2016-02-14
      • 2016-10-24
      • 1970-01-01
      • 2012-03-14
      • 2012-05-25
      相关资源
      最近更新 更多