Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine 2 and Zend 1.11 convert-mapping error..

I have a complex database design with views, relationship etc. We decided to switch to ORM from the standard Zend_db. I successfully integrated zend 1.11 and doctrine 2.1. All the tutorials out there explains about creating the entire database through hand written classes. But what about already existing database with data in it? I again searched and found out that I got to use the below command

php orm:convert-mapping --from-database php path/where/you/want/to/store/mapping/classes

When I do it for a simple database with only 3 tables and without any relationship, the above command works beautifully.

But when I tried to use the same command on my database it throws a exception saying

[Doctrine\ORM\Mapping\MappingException]

Property "employeeid" in "Organization_has_employees" was already declared, but it must be
declared only once

I changed all my field name so that there is no repeated names in any of the table but still no luck.

Please help me with this. I am breaking my head for more than 3 days.

Karthik

like image 462
Karthik Avatar asked Feb 02 '23 15:02

Karthik


1 Answers

After hours of experiment I found out the problem. Obviously it is not in Doctrine it is the database that I designed. When you do Many-To-Many tables in MySQL Workbenck you are forced to do Identifying Relationship, which create another table and create composite keys from the parent tables. Please make sure that you name this primary keys differently or if possible remove composit keys and have it as just a Non-identifying relationship. Add another column called id and have this field as a primary key and auto-numbering

Doctrine tool has a caching problem as well so please make sure that you rename the database everytime you make a change and change it in your zend config.

Hope this helps someone out there. If you still have problems please post your questions here I will be able to answer it.

like image 117
Karthik Avatar answered Feb 05 '23 06:02

Karthik