Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-117 Allow @Id on @ManyToOne fields
  3. DDC-658

Reverse engineering with Oracle (DBDriver and Associations as Identifier)

    Details

    • Type: Sub-task Sub-task
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: 2.x
    • Component/s: ORM
    • Security Level: All
    • 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.

        Activity

        Mickael Perraud created issue -
        Hide
        Mickael Perraud added a comment - - edited

        This is the continuation of http://www.doctrine-project.org/jira/browse/DDC-616. Only the schema is different.

        Show
        Mickael Perraud added a comment - - edited This is the continuation of http://www.doctrine-project.org/jira/browse/DDC-616 . Only the schema is different.
        Hide
        Benjamin Eberlei added a comment -

        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.

        Show
        Benjamin Eberlei added a comment - 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.
        Hide
        Mickael Perraud added a comment -

        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.

        Show
        Mickael Perraud added a comment - 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.
        Mickael Perraud made changes -
        Field Original Value New Value
        Description I am playing with reverse engineering with Oracle and I have some problems:

        My schema:
        {code}
        drop table TABLE_TEST2;
        drop table TABLE_TEST1;

        create table TABLE_TEST1 (
           TEST1_FIRST_COLUMN NUMBER(4) not null,
           TEST1_SECOND_COLUMN VARCHAR2(50) not null,
           TEST1_THIRD_COLUMN DATE,
           constraint PK_TABLE_TEST1 primary key (TEST1_FIRST_COLUMN)
                 using index
               tablespace TBS_INDEX
               storage
               (
                   initial 100K
                   next 100K
               )
        )
        storage
        (
            initial 100K
            next 100K
        )
        tablespace TBS_DATA;

        create table TABLE_TEST2 (
           TEST2_FIRST_COLUMN NUMBER(4) not null,
           TEST1_FIRST_COLUMN NUMBER(4) not null,
           TEST2_SECOND_COLUMN VARCHAR2(50) not null,
           TEST2_THIRD_COLUMN DATE,
           constraint PK_TABLE_TEST2 primary key (TEST2_FIRST_COLUMN, TEST1_FIRST_COLUMN)
                 using index
               tablespace TBS_INDEX
               storage
               (
                   initial 100K
                   next 100K
               )
        )
        storage
        (
            initial 100K
            next 100K
        )
        tablespace TBS_DATA;

        alter table TABLE_TEST2
           add constraint TABLE_TEST2__TABLE_TEST1 foreign key (TEST1_FIRST_COLUMN)
              references TABLE_TEST1 (TEST1_FIRST_COLUMN);
        {code}

        I obtain "Fatal error: Uncaught exception 'Doctrine\ORM\Mapping\MappingException' with message 'Property "test1FirstColumn" in "TableTest3" was already declared, but it must be declared only once'"

        It's because a foreign key is a component of the primary key.
        I am playing with reverse engineering with Oracle and I have some problems:

        My schema:
        {code}
        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);
        {code}

        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.
        Roman S. Borschel made changes -
        Assignee Roman S. Borschel [ romanb ] Benjamin Eberlei [ beberlei ]
        Benjamin Eberlei made changes -
        Parent DDC-117 [ 10344 ]
        Issue Type Bug [ 1 ] Sub-task [ 5 ]
        Hide
        Benjamin Eberlei added a comment -

        updated the issue topic to get a better grasp of what needs to be done here.

        Show
        Benjamin Eberlei added a comment - updated the issue topic to get a better grasp of what needs to be done here.
        Benjamin Eberlei made changes -
        Summary Reverse engineering with Oracle Reverse engineering with Oracle (DBDriver and Associations as Identifier)
        Hide
        waldo added a comment -

        I have the same error with Mysql whit the same condition.

        Show
        waldo added a comment - I have the same error with Mysql whit the same condition.
        Benjamin Eberlei made changes -
        Fix Version/s 2.1 [ 10022 ]
        Benjamin Eberlei made changes -
        Fix Version/s 2.x [ 10090 ]
        Fix Version/s 2.1 [ 10022 ]
        Hide
        Benjamin Eberlei added a comment -

        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().

        Show
        Benjamin Eberlei added a comment - 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().
        Hide
        Scott Steffens added a comment -

        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`),
        UNIQUE KEY `cycle_station_id` (`cycle`,`station_id`),
        KEY `station_id_idx` (`station_id`),
        KEY `readings` (`readings`),
        KEY `source` (`source`),
        KEY `temperature_min_max` (`temperature_max`,`temperature_min`),
        KEY `station_id_cycle` (`station_id`,`cycle`,`updated_at`),
        CONSTRAINT `compiled_1_station_id_stations_id` FOREIGN KEY (`station_id`) REFERENCES `stations` (`id`),
        CONSTRAINT `compiled_1_station_id_stations_id_1` FOREIGN KEY (`station_id`) REFERENCES `stations` (`id`) ON DELETE CASCADE
        ) ENGINE=InnoDB AUTO_INCREMENT=160833690 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

        Show
        Scott Steffens added a comment - 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`), UNIQUE KEY `cycle_station_id` (`cycle`,`station_id`), KEY `station_id_idx` (`station_id`), KEY `readings` (`readings`), KEY `source` (`source`), KEY `temperature_min_max` (`temperature_max`,`temperature_min`), KEY `station_id_cycle` (`station_id`,`cycle`,`updated_at`), CONSTRAINT `compiled_1_station_id_stations_id` FOREIGN KEY (`station_id`) REFERENCES `stations` (`id`), CONSTRAINT `compiled_1_station_id_stations_id_1` FOREIGN KEY (`station_id`) REFERENCES `stations` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=160833690 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
        Benjamin Eberlei made changes -
        Workflow jira [ 11559 ] jira-feedback [ 13854 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback [ 13854 ] jira-feedback2 [ 15718 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 15718 ] jira-feedback3 [ 17975 ]

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-658, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Mickael Perraud
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: