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.
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.
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.
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.
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:
Configure it in config.yml
:
doctrine: # ... orm: # ... naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
For multiple entity managers:
doctrine: # ... orm: # ... entity_managers: default: naming_strategy: doctrine.orm.naming_strategy.underscore # ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With