29

I read the chapter about Doctrine naming strategies in the manual. Unfortunately I don't understand where I have to put the configuration code.

In order to get an underscore naming strategy I should use this code:

$namingStrategy = new \Doctrine\ORM\Mapping\UnderscoreNamingStrategy(CASE_UPPER);
$configuration()->setNamingStrategy($namingStrategy);

Where should I put this?

I'm on Symfony 2 — I guess this matters when it comes to configuration.

Elnur Abdurrakhimov
  • 44,533
  • 10
  • 148
  • 133
BetaRide
  • 16,207
  • 29
  • 99
  • 177

3 Answers3

41

Configure it in config.yml:

doctrine:
    # ...

    orm:
        # ...
        naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
Nek
  • 2,715
  • 1
  • 20
  • 34
Elnur Abdurrakhimov
  • 44,533
  • 10
  • 148
  • 133
18

For multiple entity managers:

doctrine:
    # ...
    orm:
        # ...
        entity_managers:
            default:
                naming_strategy: doctrine.orm.naming_strategy.underscore
                # ...
Jekis
  • 4,274
  • 2
  • 36
  • 42
  • 2
    Ran into this issue, after adding a "default" entity manager. 'Unrecognized options "naming_strategy, a uto_mapping" under "doctrine.orm"' Pretty silly i did not figure it out. But a quick search helped pointed me here. Thanks! – Roy Jacobs Jun 13 '17 at 23:00
  • How can we solve this above an error? We are faced the same error in our symphony project. – Bhavin Thummar Jul 10 '19 at 05:59
5

If you are using a console.php file to run the CLI you might put it there.

<?php

//something...

$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);

$namingStrategy = new UpperCamelCaseNamingStrategy();
$config->setNamingStrategy($namingStrategy);

$em = EntityManager::create($dbParams, $config);

//something else...
diegopso
  • 457
  • 3
  • 11