Some useful doctrine commands

Doctrine is a very powerful tools nevertheless I use it directly only at the beginning of the project and then no more than twice a week (I don’t consider calling Doctrine functions as direct use of it).

So I am always looking for the same commands to always to the same stuff…

Here are my favourites and most useful doctrine commands (in my opinion):

Generate a new entity with the repo:
php app/console doctrine:generate:entity --entity="AcmeUserBundle:User" --with-repository

Generate entity from all tables in the DB in the annotation format
php app/console doctrine:mapping:import AcmeUserBundle annotation

Generate entity from TEST tables in the DB in the annotation format
php app/console doctrine:mapping:import --filter="TEST" AcmeUserBundle annotation

Generate getters/setters for a specific entity
php app/console doctrine:generate:entities AcmeUserBundle:User

Generate getters/setters for a whole directory specific entity
php app/console doctrine:generate:entities Acme/AcmeUserBundle/Entity

Update your DB (show queries and then executes them):
php app/console doctrine:schema:update --dump-sql --force

Obviously replace Acme with your project name and UserBundle by your effective bundle name.

Leave a Reply

Your email address will not be published. Required fields are marked *