我如何使用Symfony doctrine:fixtures:加载多个实体管理器?

时间:2014-05-23 05:00:26

标签: php symfony doctrine entitymanager fixtures

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

以下是我的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"选项,并试图加载它找到的所有数据夹具。

我如何获得doctrine:fixtures:load to only use the use entity manager?

1 个答案:

答案 0 :(得分:7)

在菲尔斯发表评论后,我将所有的灯具都移到了FixturesBundle中并完成了这个

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

对于Blog Fixtures,我还必须指定实体管理器

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