Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2059

Property perceived as dumplicate in composite foreign key

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.3
    • Fix Version/s: 2.3.1
    • Component/s: Mapping Drivers
    • Security Level: All
    • Labels:
      None

      Description

      I have the following schema:

      CREATE TABLE `user` (
        `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
        PRIMARY KEY (`id`)
      );
      
      CREATE TABLE `project` (
        `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
        `user_id` int(10) unsigned NOT NULL,
        PRIMARY KEY (`id`),
      );
      
      CREATE TABLE `project_conversation` (
        `project_id` int(10) unsigned NOT NULL,
        `user_id` int(10) unsigned NOT NULL,
        PRIMARY KEY (`project_id`,`user_id`)
      )
      

      I have ommitted the foreign key definitions for better readability. When I execute doctrine:mapping:convert (in Symfony2, but it seems it's a Doctrine2 issue), I get the following error:

      [Doctrine\ORM\Mapping\MappingException]                                               
      Property "user" in "Project" was already declared, but it must be declared only once
      

      I have tracked down the issue to be caused by the existence of `user_id` in the project table. So basically, because `project_conversation` references `project` which in turn references `user`, `project_conversation` reference to `user` is perceived as duplicate.

      I don't think that this should be the expected behavior though. user_id in `project` references the creator of the project while user_id in `project_conversation` references the creator of the conversation and thus I think the schema is valid.

        Activity

        Dimitris Bozelos created issue -
        Dimitris Bozelos made changes -
        Field Original Value New Value
        Description I have the following schema:

        CREATE TABLE `user` (
          `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
          PRIMARY KEY (`id`)
        );

        CREATE TABLE `project` (
          `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
          `user_id` int(10) unsigned NOT NULL,
          PRIMARY KEY (`id`),
        );

        CREATE TABLE `project_conversation` (
          `project_id` int(10) unsigned NOT NULL,
          `user_id` int(10) unsigned NOT NULL,
          PRIMARY KEY (`project_id`,`user_id`)
        )

        I have ommitted the foreign key definitions for better readability. When I execute doctrine:mapping:convert (in Symfony2, but it seems it's a Doctrine2 issue), I get the following error:

        [Doctrine\ORM\Mapping\MappingException]
        Property "user" in "Project" was already declared, but it must be declared only once

        I have tracked down the issue to be caused by the existence of `user_id` in the project table. So basically, because `project_conversation` references `project` which in turn references `user`, `project_conversation` reference to `user` is perceived as duplicate.

        I don't think that this should be the expected behavior though. user_id in `project` references the creator of the project while user_id in `project_conversation` references the creator of the conversation and thus I think the schema is valid.
        I have the following schema:

        {code}
        CREATE TABLE `user` (
          `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
          PRIMARY KEY (`id`)
        );

        CREATE TABLE `project` (
          `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
          `user_id` int(10) unsigned NOT NULL,
          PRIMARY KEY (`id`),
        );

        CREATE TABLE `project_conversation` (
          `project_id` int(10) unsigned NOT NULL,
          `user_id` int(10) unsigned NOT NULL,
          PRIMARY KEY (`project_id`,`user_id`)
        )
        {code}

        I have ommitted the foreign key definitions for better readability. When I execute doctrine:mapping:convert (in Symfony2, but it seems it's a Doctrine2 issue), I get the following error:

        {code}
        [Doctrine\ORM\Mapping\MappingException]
        Property "user" in "Project" was already declared, but it must be declared only once
        {code}

        I have tracked down the issue to be caused by the existence of `user_id` in the project table. So basically, because `project_conversation` references `project` which in turn references `user`, `project_conversation` reference to `user` is perceived as duplicate.

        I don't think that this should be the expected behavior though. user_id in `project` references the creator of the project while user_id in `project_conversation` references the creator of the conversation and thus I think the schema is valid.
        Benjamin Eberlei made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.2.4 [ 10322 ]
        Fix Version/s 2.3.1 [ 10323 ]
        Resolution Fixed [ 1 ]
        Guilherme Blanco made changes -
        Fix Version/s 2.2.4 [ 10322 ]

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Dimitris Bozelos
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: