创建bundle以使用具有不同连接的辅助实体管理器



我正在创建一个捆绑包,用于从辅助数据库中提取数据。我不确定我可以添加或更改哪些其他配置来实现这一点。我还尝试将连接直接传递到存储库中。理想情况下,使用捆绑包的工具只能将存储库作为参数传递并轻松使用

给出的错误:

The class 'SRCSRCDataBundleEntityCourse' was not found in the chain configured namespaces

导入捆绑包的工具中的doctrine.yml文件。SECONDARY_DATA是我试图将实体管理器连接到的数据

doctrine:
dbal:
default_connection: default
connections:
default:
# configure these for your database server
driver: 'pdo_mysql'
server_version: '5.6'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
url: '%env(DATABASE_URL)%'
SECONDARY_DATA_CONN:
# configure these for your database server
driver: 'pdo_mysql'
server_version: '5.6'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
url: '%env(SECONDARY_DATABASE_URL)%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
default_entity_manager: default
entity_managers:
default:
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
connection: default
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'AppEntity'
alias: App
SECONDARY_DATA:
naming_strategy: doctrine.orm.naming_strategy.underscore
connection: SECONDARY_DATA_CONN
auto_mapping: false

主工具的services.yml文件。出于隐私原因,我更改了一些路径和名称。

SRCSRCDataBundleEntityRepositoryCourseRepository:
alias: 'src.src.data_bundle.course.repository'

捆绑的services.yml文件

services:
src.src.data_bundle.course.repository:
class: SRCSRCDataBundleEntityRepositoryCourseRepository
factory: ['@doctrine.orm.SECONDARY_DATA_entity_manager', getRepository] # where i believe the entity manager will know to use the correct database
public: false
arguments:
- 'SRCSRCDataBundleEntityCourse'

存储库文件

namespace SRCSRCDataBundleEntityRepository;
use DoctrineBundleDoctrineBundleRepositoryServiceEntityRepository;
class CourseRepository extends ServiceEntityRepository
{}

这就是我最终使用ORM条目上的映射来解决它的方法

SECONDARY_data:
naming_strategy: doctrine.orm.naming_strategy.underscore
connection: SECONDRARY_data_CONN
auto_mapping: false
mappings:
DataBundle:
type: annotation
prefix: UCIAWTDataBundleEntity
dir: "%kernel.project_dir%/.../.../data-bundle/Entity"
is_bundle: false

最新更新