Thursday, January 16, 2014

How to generate doctrine entities from database

Following command is executed from /home/projects/zend-skeleton/vendor/bin folder:
  
./doctrine-module orm:convert-mapping --from-database annotation --namespace="Application\Entity\\" 
/home/projects/zendskeleton/module/Application/src
Note: In the latest version of doctrine module you can also run it from project root directory like this:
  php public/index.php orm:convert-mapping --from-database annotation --namespace="Application\Entity\\" 
/home/projects/zendskeleton/module/Application/src
Generated entities will be in folder /home/projects/zendskeleton/module/Application/src/Application/Entity/ and will have namespace Application\Entity. If you have enum types in the database you have to add following lines to application configuration:

 'doctrine_type_mappings' => array(
  'enum' => 'string'
 );
  
so it looks like this:

 array(
        'connection' => array(
            'orm_default' => array(
               'driverClass'=>'Doctrine\DBAL\Driver\PDOMySql\Driver',
               'params'      => array(
                   'host'     => 'localhost',
                   'dbname'   => 'xxxx',
                   'user'     => 'xxxx',
                   'password' => 'xxxx'
               ),
               'doctrine_type_mappings' => array(
                   'enum' => 'string'
               )
            ),
        )
    )
);
  

No comments:

Post a Comment