3

So I'm trying to do a multiple connection with doctrine in my symfony project.

First, I was only using one database, then I needed to add another.

this was before :

# Doctrine Configuration
doctrine:
  dbal:
    default_connection: extranet
    connections:
        extranet:
            driver:   pdo_mysql
            host:     "%db_extranet_host%"
            port:     "%db_extranet_port%"
            dbname:   "%db_extranet_name%"
            user:     "%db_extranet_user%"
            password: "%db_extranet_password%"
            charset:  UTF8
orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    entity_managers:
        extranet:
            naming_strategy: doctrine.orm.naming_strategy.underscore
            auto_mapping: true

and it was working fine

THEN I added the "crawl" database :

# Doctrine Configuration
doctrine:
  dbal:
    default_connection: extranet
    connections:
        extranet:
            driver:   pdo_mysql
            host:     "%db_extranet_host%"
            port:     "%db_extranet_port%"
            dbname:   "%db_extranet_name%"
            user:     "%db_extranet_user%"
            password: "%db_extranet_password%"
            charset:  UTF8
        crawl:
            driver:   pdo_mysql
            host:     "%db_crawl_host%"
            port:     "%db_crawl_port%"
            dbname:   "%db_crawl_name%"
            user:     "%db_crawl_user%"
            password: "%db_crawl_password%"
            charset:  UTF8
orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    default_entity_manager: extranet
    entity_managers:
        extranet:
            connection: extranet
            naming_strategy: doctrine.orm.naming_strategy.underscore
            mappings:
                AppBundle: ~
        crawl:
            connection: crawl
            naming_strategy: doctrine.orm.naming_strategy.underscore
            mappings:
                DbBccCrawlBundle: ~

I got rid of the auto_mapping & added few things

BUT, now I lost connection to extranet (users can't loggin anymore for example)

Any ideas? (and thanks if you read that far ;) )

EDIT

following http://symfony.com/doc/2.3/reference/configuration/doctrine.html#mapping-entities-outside-of-a-bundle I tried to have the same syntax :

orm:
    # auto_generate_proxy_classes: "%kernel.debug%"
    default_entity_manager: extranet
    # auto_mapping: true
    mappings:
        AppBundle:
            type: annotation
            dir: '%kernel.root_dir%/../src/AppBundle/Entity'
            prefix: AppBundle\Entity
            alias: App
        DbBccCrawlBundle:
            type: annotation
            dir: '%kernel.root_dir%/../src/DbBccCrawlBundle/Entity'
            prefix: DbBccCrawlBundle\Entity
            alias: Crawl

still doesn't work....

EDIT 2

orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    default_entity_manager: extranet
    entity_managers:
        auto_mapping: true
        extranet:
            connection: extranet
            naming_strategy: doctrine.orm.naming_strategy.underscore
            mappings:
                AppBundle:
                    type:   annotation
                    # dir:    '%kernel.root_dir%/../src/AppBundle/Entity'
                    # prefix: AppBundle\Entity
                    alias:  App
        crawl:
            connection: crawl
            naming_strategy: doctrine.orm.naming_strategy.underscore
            mappings:
                DbBccCrawlBundle:
                    type:   annotation
                    # dir:    '%kernel.root_dir%/../src/DbBccCrawlBundle/Entity'
                    # prefix: DbBccCrawlBundle\Entity
                    alias:  Crawl

not working either

Fire Frost
  • 95
  • 1
  • 14
  • Did you read http://symfony.com/doc/current/doctrine/multiple_entity_managers.html? How do you build your connections currently? – Sebastian Apr 05 '17 at 09:19
  • Yup, read that few times already. I use webservices for most of my queries but I need a table that stores some recurent information... – Fire Frost Apr 05 '17 at 09:22
  • found this website (cause I'm on SF 2.3) : http://symfony.com/doc/2.3/reference/configuration/doctrine.html – Fire Frost Apr 05 '17 at 09:28
  • Does it work now? If not, do you have some PHP code for us? – Sebastian Apr 05 '17 at 09:42
  • okay, tried to have the same syntax/format but still doesn't connect... (at the "Mapping Entities Outside of a Bundle" section) – Fire Frost Apr 05 '17 at 09:51
  • what part of the code could help ? If I'm right, the code I've posted is what links my project to my database .... just realised something, gotta check something – Fire Frost Apr 05 '17 at 09:58
  • I was checking that I was pointing to the right Entity, the problem might be there... `$em = $this->get('doctrine')->getEntityManager('default');` `$em = $this->get('doctrine')->getEntityManager('another');` – Fire Frost Apr 05 '17 at 10:04
  • Did you try $this->get('doctrine')->getEntityManager(); or $this->get('doctrine')->getEntityManager('extranet'); – Sebastian Apr 05 '17 at 10:16
  • May be you need to check http://stackoverflow.com/questions/43041832/symfony-3-entitymanager-dependency-injection-with-multiple-db-connections/43042335#43042335 – Maulik Savaliya Apr 05 '17 at 11:02
  • tried, no result... & I update the code – Fire Frost Apr 05 '17 at 11:39

1 Answers1

2

I donno why/how but it works

here's the code :

orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    entity_managers:
        extranet:
            naming_strategy: doctrine.orm.naming_strategy.underscore
            auto_mapping: true
        crawl:
            naming_strategy: doctrine.orm.naming_strategy.underscore
            connection: crawl
            mappings:
                DbBccCrawlBundle: ~

the thing is that I tried that at the start and it failed (the class X not found in...)

If anyone has an explenation, I'll be more than happy to read it.

Thanks anyway

This was the 2nd part of the question, here's the begening : The class 'X' was not found in the chain configured namespaces ... when I try a multiple connection with doctrine

Community
  • 1
  • 1
Fire Frost
  • 95
  • 1
  • 14