我希望有两个实体管理器,一个用于为包中定义的实体定义的SQLite数据库,另一个用于主应用程序。这样,我就可以将从未更改过的数据加载到一个数据库中,并将固定装置、测试等加载到应用程序数据库中。我希望下面的代码可以转储包实体的sql,但它没有:
bin/console doctrine:schema:update --dump-sql --em=geonames
[OK] No Metadata Classes to process. 类似地,我希望easyadmin允许我为包实体定义类,但它也失败了。
# easy_admin.yaml
entities:
Administrative:
class: Bordeux\Bundle\GeoNameBundle\Entity\Administrative路径“"Bordeux\Bundle\GeoNameBundle\Entity\Administrative”“的配置类easy_admin.entities.Administrative不是映射的实体。
我希望它与名称空间有关,或者可能与is_bundle参数有关。我花了几个小时对此进行了黑客操作,并遵循了关于多个实体管理器的教程和文档,但我找不到任何东西显示如何处理来自第三方包的实体。
# doctrine.yaml
doctrine:
dbal:
default_connection: default
connections:
default:
url: '%env(resolve:DATABASE_URL)%'
geonames:
url: '%env(DATABASE_GEONAMES_URL)%'
orm:
default_entity_manager: default
entity_managers:
default:
connection: default
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
geonames:
connection: geonames
mappings:
BordeuxGeoNameBundle:
is_bundle: true
type: annotation
dir: 'Entity'
prefix: 'Geonames\Entity'
alias: Geonames发布于 2020-04-07 13:01:46
我还没有为最新的和最伟大的Symfony版本配置多个实体管理器,所以我设置了一个小的测试用例,并为配置提供了这个测试用例:
orm:
default_entity_manager: default
auto_generate_proxy_classes: true
entity_managers:
default:
connection: default
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
geonames:
connection: geonames
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
mappings:
BordeuxGeoNameBundle:
is_bundle: true
type: annotation
dir: 'Entity'
prefix: 'Bordeux\Bundle\GeoNameBundle\Entity'
alias: GeoNames我用以下方法测试了它:
bin/console doctrine:mapping:info --em=geonames并确认这些实体被绘制成地图。我没有安装EasyAdmin并对其进行测试,但是我不知道为什么它不能工作。
主要的区别是使用实体名称空间作为前缀属性。
为了我将来的参考,我将测试项目提交给了github。
https://stackoverflow.com/questions/61078458
复制相似问题