6

I'm trying to add the "enum" type to my symfony2 dbal connection, but I can't find a way to do it.

doctrine:
    dbal:
        mapping_types:
            enum: string
        default_connection: default
        connections:
            default:
                  driver:   "%database_driver%"
                  host:     "%database_host%"
                  port:     "%database_port%"
                  dbname:   "%database_name%"
                  user:     "%database_user%"
                  password: "%database_password%"
                  charset:  UTF8
            connection2:
                  driver:   "%database2_driver%"
                  host:     "%database2_host%"
                  port:     "%database2_port%"
                  dbname:   "%database2_name%"
                  user:     "%database2_user%"
                  password: "%database2_password%"
                  charset:  LATIN1

This is my config right now and I'm getting the error:

  [Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]  
  Unrecognized option "mapping_types" under "doctrine.dbal"    

I also tried to place it beneath the connection2 and removed the default_connection since I found answers that solved the problem like this. But these questions haven't had multiple connections.

Matteo
  • 37,680
  • 11
  • 100
  • 115
KhorneHoly
  • 4,666
  • 6
  • 43
  • 75

2 Answers2

13

mapping_types must be located under concrete connection. So you need next config:

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                  mapping_types:
                      enum: string
                  driver:   "%database_driver%"
                  host:     "%database_host%"
                  port:     "%database_port%"
                  dbname:   "%database_name%"
                  user:     "%database_user%"
                  password: "%database_password%"
                  charset:  UTF8
            connection2:
                  mapping_types:
                      enum: string
                  driver:   "%database2_driver%"
                  host:     "%database2_host%"
                  port:     "%database2_port%"
                  dbname:   "%database2_name%"
                  user:     "%database2_user%"
                  password: "%database2_password%"
                  charset:  LATIN1
Michael Sivolobov
  • 12,388
  • 3
  • 43
  • 64
  • You are correct, but this is not how the Symfony docs described the Doctrine configuration. See https://symfony.com/doc/3.3/reference/configuration/doctrine.html#doctrine-dbal-configuration. The example clear shows mapping_types within doctrine.dbal itself. – JasonGabler Nov 07 '19 at 23:32
  • 1
    @JasonGabler, in the provided documentation there is no information about where key `mapping_types` live if there exist several connections. But you can draw an analogy with other keys from connection. The key `mapping_types` depends on `connection` in the same way as `driver` or `host` so they should be at one block under concrete connection. – Michael Sivolobov Nov 10 '19 at 14:06
1

in according with the full reference, you must set the mapping_typesunder the specified connection element.

Check here for further detail

hope this help

Matteo
  • 37,680
  • 11
  • 100
  • 115
  • You are correct, but this is not how the Symfony docs described the Doctrine configuration. In the link to the Symfony docs you provide, the example clear shows mapping_types within doctrine.dbal itself. – JasonGabler Nov 07 '19 at 23:33