【问题标题】:How do I use Symfony doctrine:fixtures:load with multiple entity managers?如何将 Symfony 学说:fixtures:load 与多个实体管理器一起使用?
【发布时间】:2014-07-12 08:13:08
【问题描述】:

我已经设置了一个包含多个实体管理器的新项目,当我尝试加载数据夹具时,我得到一个 MappingException,因为控制台尝试为所有内容而不是我指定的实体管理器加载夹具。

这是我的 config.yml 中的教义部分

doctrine:
    dbal:
        connections:
            default:
                driver:   %database_driver%
                host:     %database_host%
                port:     %database_port%
                dbname:   %database_name%
                user:     %database_user%
                password: %database_password%
                charset:  %database_charset%
            symblog:
                driver:   %database_driver_blog%
                host:     %database_host_blog%
                port:     %database_port_blog%
                dbname:   %database_name_blog%
                user:     %database_user_blog%
                password: %database_password_blog%
                charset:  %database_charset_blog%

    orm:
        auto_generate_proxy_classes: %kernel.debug%
        entity_managers:
            default:
                connection: default
                mappings:
                    IncompassAuthBundle: ~
                    IncompassUserBundle: ~
                    IncompassApiBundle: ~
                    IncompassSurgeryBundle:  ~
                    IncompassVendorBundle:  ~
                    IncompassHospitalBundle:  ~
                dql:
                    datetime_functions:
                        date: Mapado\MysqlDoctrineFunctions\DQL\MysqlDate
            symblog:
                connection: symblog
                mappings:
                    IncompassBlogBundle: ~
                dql:
                    datetime_functions:
                        date: Mapado\MysqlDoctrineFunctions\DQL\MysqlDate

如您所见,我为 symblog 教程设置了单独的连接和实体管理器。

当我尝试时

php app/console doctrine:fixtures:load --em=default

我明白了

Careful, database will be purged. Do you want to continue Y/N ?Y
  > purging database
  > loading [1] Incompass\BlogBundle\DataFixtures\ORM\BlogFixtures

  [Doctrine\Common\Persistence\Mapping\MappingException]                                                                                                              
  The class 'Incompass\BlogBundle\Entity\Blog' was not found in the chain configured namespaces Incompass\AuthBundle\Entity, Incompass\UserBundle\Entity, Incompass\  
  SurgeryBundle\Entity, Incompass\VendorBundle\Entity, Incompass\HospitalBundle\Entity, FOS\UserBundle\Model                                                          

doctrine:fixtures:load [--fixtures[="..."]] [--append] [--em="..."] [--purge-with-truncate]

当我尝试时

php app/console doctrine:fixtures:load --em=symblog

我明白了

Careful, database will be purged. Do you want to continue Y/N ?Y
  > purging database
  > loading [1] Incompass\BlogBundle\DataFixtures\ORM\BlogFixtures
  > loading [1] Incompass\SurgeryBundle\DataFixtures\ORM\SurgeryStatusFixtures

  [Doctrine\Common\Persistence\Mapping\MappingException]                                                                                 
  The class 'Incompass\SurgeryBundle\Entity\SurgeryStatus' was not found in the chain configured namespaces Incompass\BlogBundle\Entity  

doctrine:fixtures:load [--fixtures[="..."]] [--append] [--em="..."] [--purge-with-truncate]

所以控制台命令似乎忽略了“--em=foobar”选项,并试图加载它找到的所有数据固定装置。

我怎样才能让学说:fixtures:load 只使用指定的实体管理器?

【问题讨论】:

  • 我认为它不会通过提供的实体管理器过滤固定装置。您应该做的是指定 --fixtures 路径

标签: php symfony doctrine entitymanager fixtures


【解决方案1】:

在 Phils 发表评论后,我将所有的 Fixtures 都移到了 FixturesBundle 中并这样做了

php app/console doctrine:fixtures:load --fixtures=src/Incompass/FixturesBundle/DataFixtures/ORM

对于博客装置,我还必须指定实体管理器

php app/console doctrine:fixtures:load --fixtures=src/Incompass/BlogBundle/DataFixtures/ORM --em=symblog

【讨论】:

    猜你喜欢
    • 2020-04-03
    • 2016-01-02
    • 2016-04-21
    • 2013-05-03
    • 2015-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多