Allow @Id on @ManyToOne fields
(DDC-117)
|
|
| Status: | Open |
| Project: | Doctrine 2 - ORM |
| Component/s: | ORM |
| Affects Version/s: | None |
| Fix Version/s: | 2.x |
| Security Level: | All |
| Type: | Sub-task | Priority: | Major |
| Reporter: | Mickael Perraud | Assignee: | Benjamin Eberlei |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | None | ||
| Environment: |
Ubuntu 10.04 + Oracle 11g Entreprise + PHP 5.3.2 + Doctrine2 Git (up-to-date) |
||
| Description |
|
I am playing with reverse engineering with Oracle and I have some problems: My schema: drop table PHONE_NUMBER; drop table CUSTOMER; create table CUSTOMER ( CUSTOMER_ID NUMBER(4) not null, CUSTOMER_LASTNAME VARCHAR2(50) not null, CUSTOMER_MODIFIED DATE, constraint PK_CUSTOMER primary key (CUSTOMER_ID) using index tablespace TBS_INDEX storage ( initial 100K next 100K ) ) storage ( initial 100K next 100K ) tablespace TBS_DATA; create table PHONE_NUMBER ( PHONE_NUMBER_ID NUMBER(4) not null, CUSTOMER_ID NUMBER(4) not null, PHONE_NUMBER VARCHAR2(50) not null, PHONE_NUMBERMODIFIED DATE, constraint PK_PHONE_NUMBER primary key (PHONE_NUMBER_ID, CUSTOMER_ID) using index tablespace TBS_INDEX storage ( initial 100K next 100K ) ) storage ( initial 100K next 100K ) tablespace TBS_DATA; alter table PHONE_NUMBER add constraint PHONE_NUMBER__CUSTOMER foreign key (CUSTOMER_ID) references CUSTOMER (CUSTOMER_ID); I obtain "Fatal error: Uncaught exception 'Doctrine\ORM\Mapping\MappingException' with message 'Property "customerId" in "PhoneNumber" was already declared, but it must be declared only once'" It's because a foreign key is a component of the primary key. |
| Comments |
| Comment by Mickael Perraud [ 28/Jun/10 ] |
|
This is the continuation of http://www.doctrine-project.org/jira/browse/DDC-616. Only the schema is different. |
| Comment by Benjamin Eberlei [ 28/Jun/10 ] |
|
just for understanding this scenario: Is this a One-To-One relation and the TABLE_TEST2 "inherits" the primary key from its parent TABLE_TEST1? If yes, this construct is not yet supported by Doctrine 2, we still need to include an ID-Generator that supports this kind of schema. |
| Comment by Mickael Perraud [ 28/Jun/10 ] |
|
Change for a more understandable use case. Note that it's not my real use case and that I work on legacy database on which I can't change the structure. |
| Comment by Benjamin Eberlei [ 01/Jan/11 ] |
|
updated the issue topic to get a better grasp of what needs to be done here. |
| Comment by waldo [ 09/Jun/11 ] |
|
I have the same error with Mysql whit the same condition. |
| Comment by Benjamin Eberlei [ 28/Nov/11 ] |
|
More details on the work to be done: The relevant code is in Doctrine/ORM/Mapping/Driver/DatabaseDriver.php only. The idea is currently many-to-many tables are detected by checking that the table has foreign keys on all the primary key columns (no additional columns!) Now with the 2.1 feature of foreign key/primary key entities this is not necessarily true anymore. You can have the primary keys being foreign keys BUT have additional columns that are not part of the primary key. This has to be detected. If a foreign key-primary-key entity is found that has additional columns a ClassMetadata has to be created and the associations have to be created with the "id" => true flag in mapManyToOne(). |
| Comment by Scott Steffens [ 11/Dec/11 ] |
|
For what it's worth, I'm getting this error when I have a PK that is a single column and not a FK. PRIMARY KEY (`id`), |