Is it possible to create model classes using Doctrine 2 directly from the database?

I am in the process of upgrading from Doctrine 1.1.4 to Doctrine 2.0.6 in my Zend application. I installed the Doctrine 2 command line tool.

In Doctrine 1.1.4, I generated model classes directly from the database (using Doctrine :: generateModelsFromDb ()), is this possible in Doctrine 2 or do I need to go through the 'mapping' process, i.e. Docblock Annotations, XML, or YAML table structures.

The reason I'm asking about this is because Doctrine 2 has the setAutoGenerateProxyClass option, I got the impression that this means that it will generate proxy classes from scratch.

Rate the help.

+6
source share
2 answers

Autogenerate proxyclasses basically means that Doctrine 2 automatically generates "proxy classes" for your objects instead of only generating them manually using generate-proxies. Proxies are used when you have relationships in your entities, and they should be lazy.

To create mapping information from a database, you can use transform-transform:

php doctrine orm:convert-mapping --from-database yml /path/to/mapping-path-converted-to-yml 

Remember that this is only recommended as a starting point. The database driver cannot correctly generate mappings for all possible combinations of parameters, so you probably should just run it once and then write the mappings yourself.

See the Doctrine 2 Reverse Database Design Guide

+6
source

You can use the "annotation" as a driver if you want to get the generated objects:

 php doctrine orm:convert-mapping --from-database annotation generatedModels 
+3
source

Source: https://habr.com/ru/post/892511/


All Articles