Doctrine 2 and Zend 1.11 convert-mapping error..
Asked Answered
T

1

9

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

Tansey answered 28/7, 2011 at 19:48 Comment(0)
T
12

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.

Tansey answered 28/7, 2011 at 19:48 Comment(4)
I'm having the same problem (error), with doctrine:schema:create. The database is empty. Doctrine is throwing: Property "organisation" in "myApp\PersonBundle\Entity\Contact" was already declared, but it must be declared only onceSybilla
@Sybilla Ya its bit of a pain... Have you tried changing the fieldnames to something unique?Tansey
Hi @Karthik. I have the same problem. I do not know exactly what I need to remove or edit. Can I give you my *. MWB file? Thanks in advance..Abroms
Hello Puzo, I wish I could help. It been so long, I forgot where I kept these files..Tansey

© 2022 - 2024 — McMap. All rights reserved.