Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend 1.11 and Doctrine 2 Auto generate everything needed from already existing database

I am new to ORM and I am really keen to learn it. I successfully managed to install all classes and configurations for Doctrine 2.1 with Zend 1.11.x by following this tutorial.

http://www.zendcasts.com/unit-testing-doctrine-2-entities/2011/02/ Which uses Bisna plugin and doctrine scripts.

Now my problem is he is clearly explaining how to create entities and tables through doctrine classes but do not explain how to auto generate the proxies and repo classes from already existing database which helps me to select, insert and update. I always create my databases using MySQL Workbench.

I also followed the below tutorial as well

http://www.zend.com/en/webinar/Framework/70170000000bSrG-webinar-zf-v-1-doctrine-v-2-20101214.flv

My database is so complex with relationship flowing across every possible way. If I follow the steps which is explained in these tutorials I will never complete my project. Can any one please explain how to start using Doctrine after configuration. Considering I already have a database and my Model folders are empty. I have my folder sructure as below.

    C:/zf/library/Doctrine
    C:/zf/library/Symfony
    C:/zf/library/ZC -- (my model which should contain the proxies and repo of Doctrine. At the moment it contains nothing.)
    C:/zf/library/Zend
C:/zf/scripts/doctrine.php

Please help me!

I posted this same post yesterday and no one replied to my post. Please let me know if you need anymore information from me.

Thank you,

Karthik

like image 917
Karthik Avatar asked Jul 26 '11 17:07

Karthik


1 Answers

According to Doctrine you should create your entities first yourself and then create your database schema from these entities.

But because you already have a database you probably don't want that. It is possible to convert your database to Doctrine2 entities in PHP, XML or Yaml.

You should take a closer look at the commandline tools Doctrine offers with the Bisna glue because there you can generate a lot of stuff.

To generate your entities FROM your database consider the following command:

php doctrine.php orm:convert-mapping --from-database php ../library/Application/Entity

You can also define the namespace and a base class which your entities have to extends with: --namespace=namespace and --extends=class.

Doctrine2 warns you to convert your database to entities because not everything could be auto detected or supported. For instance ENUM datatypes are not supported by default in Doctrine2 so converting your database will raise an error.

It's a good idea to check all your entities especially associations before you use them. Hope it helps you.

like image 189
Kees Schepers Avatar answered Sep 28 '22 16:09

Kees Schepers