Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure naming strategy in Doctrine 2

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.

like image 291
BetaRide Avatar asked Oct 03 '12 06:10

BetaRide


People also ask

What are entity repositories in Doctrine2?

The similar concept in Doctrine2 is called Entity Repositories, integrating the repository pattern at the heart of Doctrine. Every Entity uses a default repository by default and offers a bunch of convenience methods that you can use to query for instances of that Entity.

How do I install doctrine with Symfony?

Install Doctrine using the Composer Dependency Management tool, by calling: This will install the packages Doctrine Common, Doctrine DBAL, Doctrine ORM, Symfony YAML and Symfony Console into the vendor directory. The Symfony dependencies are not required by Doctrine but will be used in this tutorial.

Does doctrine 2 work with lower versions of PHP?

Some of the code will not work with lower versions. Doctrine 2 is an object-relational mapper (ORM) for PHP 5.4+ that provides transparent persistence for PHP objects. It uses the Data Mapper pattern at the heart, aiming for a complete separation of your domain/business logic from the persistence in a relational database management system.

What is EntityManager in doctrine 2?

Doctrine’s public interface is the EntityManager, it provides the access point to the complete lifecycle management of your entities and transforms entities from and back to persistence. You have to configure and create it to use your entities with Doctrine 2. I will show the configuration steps and then discuss them step by step:


2 Answers

Configure it in config.yml:

doctrine:     # ...      orm:         # ...         naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware 
like image 153
Elnur Abdurrakhimov Avatar answered Oct 09 '22 12:10

Elnur Abdurrakhimov


For multiple entity managers:

doctrine:     # ...     orm:         # ...         entity_managers:             default:                 naming_strategy: doctrine.orm.naming_strategy.underscore                 # ... 
like image 39
Jekis Avatar answered Oct 09 '22 12:10

Jekis