Symfony 2.8 : Doctrine getManagerForClass() not returning the right Entity Manager

前端 未结 1 1699
耶瑟儿~
耶瑟儿~ 2021-01-15 11:29

tl;dr How does the getManagerForClass() method find out which entity manager is the right one for a specific class?

I\'ve made a generic controller that

相关标签:
1条回答
  • 2021-01-15 12:32

    At long last, I solved it. The solution was using the prefix parameter.

    entity_managers:
        postgres:
            connection: postgres
            mappings:
                AppBundle:
                    type: annotation
                    dir: Entity\Postgres
                    prefix: AppBundle\Entity\Postgres
                    alias: Postgres
        oracle:
            connection: oracle
            mappings:
                AppBundle:
                    type: annotation
                    dir: Entity\Oracle
                    prefix: AppBundle\Entity\Oracle
                    alias: Oracle
    

    Explanation

    The prefix parameter gets passed to the corresponding Entity Manager service, and is added to the entityNamespaces property, which otherwise defaults to AppBundle/Entity. The Annotation Driver will then check for annotations in that specific namespace, whereas the File Driver checks for existing mapping files in the directory specified through the dir parameter. (The alias parameter is not mandatory.)

    At least, that's how I understand it.

    0 讨论(0)
提交回复
热议问题