symfony - 如何为单个实体使用 XML 映射并保持由注释映射的其余实体?
问题描述
我正在向基于 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
解决方案
是的,您需要禁用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
推荐阅读
- java - micronaut 框架是否支持将日志配置为 json?
- php - 将数组分配给php字符串
- c# - 不允许更改对象
- dask - dask 数据帧处理速度是否随工人数量线性增加?
- c# - C#-Selenium:在 windows 文件上传弹出窗口的“文件名:”文本框中粘贴文件路径。不能使用“SendKeys”
- javascript - Youtube iframe 在谷歌集线器上加载时无法在谷歌交互式画布上运行
- spring - 如何使用 Spring config 重新启动 ignite 服务器?
- javascript - Javascript - 使对象中的函数全局
- npm - Webpack 3:如何从编译检查中排除文件夹?
- python - 无法安装 librosa