Symfony2 Creating Doctrine Objects from .yml Files

So, I have an existing database, but I could not follow the steps described here: http://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html , because some of my tables have foreign keys for primary keys .

My solution was to create a copy of the database without foreign key restrictions and first generate .yaml files with THAT.

So now I have XXX.orm.yml./src/My/MainBundle/Resources/config/doctrine/metadata/orm files

Then I tried to turn these .yml files into Entity classes with annotations using this command: php app / console doctrine: mapping: import MyMainBundle annotation However, this ignores my .yml files. It either generates common classes from my database without foreign keys, or it generates an error if I use it in my real database. He doesn't even look at my .yml files.

So, all I want to know is, how can I convert * .orm.yml files to Entities?

+4
source share
3 answers

I'm not 100% sure if this is all I needed to do to fix it, but I think the solution was as simple as moving my .orm.yml files from

./src/My/MainBundle/Resources/config/doctrine/metadata/orm 

to

 ./src/My/MainBundle/Resources/config/doctrine 

and working

 php app/console doctrine:mapping:import MyMainBundle annotation --path="./src" 
+4
source

- the path is not an option for the doctrine: mapping: import command

+2
source

Use convert after import to convert yaml to object annotations:

 php bin/console doctrine:mapping:convert annotation src 

See Help for more information.

To force an override of entity files, use the -force option.

To create accessories (recipients and setters) use

 php bin/console doctrine:generate:entities yourBundle 

Be sure to check to see if yml files change the behavior of annotation changes ...

Hi

+2
source

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