4
votes

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

My solution has been to create a copy of the database without foreign key constraints and generate the .yaml files from THAT first.

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

Next I tried to turn these .yml files into Entity classes with annotations by using this command: php app/console doctrine:mapping:import MyMainBundle annotation However that ignores my .yml files. It either generates the generic classes from my database without foreign keys, or it throws an error if I use it on my real database. It never even looks at my .yml files.

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

4
Somehow I got this working, but I've gotta say that the documentation on doing this was very poor and I had to do something differently...Matt
Hi. You should post your solution and mark it as answered. I've been looking into Doctrine's reverse engineering the last couple of days and I'd be curious to see your approach.Darragh Enright
I think the answer below is what worked, can't remember for sure but I'll mark it answered as soon as SO lets me.Matt
Having a same problem, but not able to get it running.. How to convert .yml file to entities.. I am losing hours to figure out due to improper documentation. code (C:\Users\Umra\myBookShop>php app\console doctrine:mapping:import AppBundle annotation --path="./src" Warning: Module 'openssl' already loaded in Unknown on line 0 Warning: Module 'openssl' already loaded in Unknown on line 0 [Symfony\Component\Console\Exception\RuntimeException] The "--path" option does not exist.)NadZ

4 Answers

4
votes

I'm not 100% sure if this is all I had 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 running

php app/console doctrine:mapping:import MyMainBundle annotation --path="./src"
3
votes

Use convert after import to convert yaml to entity annotations :

php bin/console doctrine:mapping:convert annotation src

See --help for further informations.

To force override entity files use --force option.

To create accessors (getters and setters) use

php bin/console doctrine:generate:entities yourBundle

Don't forget to check if yml files don't override behavior of annotation changes...

Regards

2
votes

--path isn't an option to the command doctrine:mapping:import

0
votes

after:

php bin/console doctrine:mapping:import YourBundle yml

use:

php bin/console doctrine:generate:entities YourBundle