Doctrine 2和Zend 1.11转换映射错误..

问题描述:

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

我有一个复杂的数据库设计,包含视图,关系等。我们决定从标准Zend_db切换到ORM。 我成功地整合了zend 1.11和doctrine 2.1。 所有教程都解释了如何通过手写类创建整个数据库。 但是现有数据库中有数据呢? 我再次搜索并发现我必须使用以下命令 p>

  php orm:convert-mapping --from-database php path / where / you / want / to / 存储/映射/类
  code>  pre> 
 
 

当我为一个只有3个表且没有任何关系的简单数据库执行此操作时,上述命令可以很好地工作。 p> \ n

但是当我尝试在我的数据库上使用相同的命令时,它会抛出一个异常,说 p>

  [Doctrine \ ORM \ Mapping \ MappingException] 
 
Property 已经声明了“Organization_has_employees”中的“employeeid”,但它必须只有一次
  code>  pre> 
 
 

我更改了所有字段名称,以便没有重复的名称 任何一张桌子,但仍然没有运气。 p>

请帮帮我。 我突破了3天以上。 p>

Karthik p> div>

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.