8
votes

I have setup a new project with multiple entity managers, when I try to load the data fixtures I get an MappingException as the console tries to load Fixtures for everything rather than the entity manager I specified.

Here is the doctrine section from my 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

As you can see I've setup a separate connection and entity manager for the symblog tutorial stuff.

When I try

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

I get this

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]

When I try

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

I get

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]

So the console command appears to be ignoring the "--em=foobar" option and is trying to load up all the data fixtures it finds.

How can I get doctrine:fixtures:load to only use the specified entity manager?

1
I don't think it's going to filter fixtures by the entity manager supplied. What you should be doing is specifying the --fixtures path(s)Phil

1 Answers

8
votes

After Phils comment I moved all my Fixtures into a FixturesBundle and did this

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

For the Blog Fixtures I also had to specify the entity manager

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