开发者

Generating mapping information on existing database use Doctrine 2

I've got Doctrine 2 set up on Zend Framework 1.10 and have all the autoloading set up correctly including all necessary config settings in the application.ini. What I need to do now (or so I believe) is to create my Entity classes with mapping information so that the entity manager can work with my database.

What I don't want to do is write the Entity classes by hand as this will take ages but I can't seem to work out what to do next. Does the command line tool have functionality to开发者_StackOverflow create the entities, proxies and all other necessary classes from an existing schema?


You can use the reverse engineering tool of Doctrine http://www.doctrine-project.org/docs/orm/2.0/en/reference/tools.html#reverse-engineering

But it also doesnt detect everything as noted in the reference.

Your best bet is to reverse engineer and filling the rest with manually IMO.


Using the command line tool:

 ./bin/doctrine orm:convert-mapping --from-database xml ./bin/tmp

This will generate your xml mappings. Then, ensure that when configuring Doctrine CLI tool you change the driver to the XmlDriver

$driver = new \Doctrine\ORM\Mapping\Driver\XmlDriver(array(
    APPLICATION_PATH . '/../bin/tmp'             
));
$config->setMetadataDriverImpl($driver);

My CLI configuration uses Zend_Application, so I'm usually changing this in my Bootstrap.

Now run

./bin/doctrine orm:generate-entities ./bin/tmp

The Xml Metadata Driver is required in order for orm:generate-entities to convert from xml to entities. If you use the Default Annotation Driver, it will convert entities in the annotation driver path to entities which is not what we want here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜