Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-759

More than one many-to-many relations cannot be created using default values

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: 2.0-BETA4
    • Fix Version/s: 2.0-RC1
    • Component/s: Mapping Drivers
    • Security Level: All
    • Labels:
      None

      Description

      An entity that has two many to many fields that referrence the same entity can't exist on its own, because ClassMetadataInfo uses the actual name of the referrenced entity to define joining table.

      When there are for example Product and TextFile entities and you want to assigng the TextFile entitites to the Product entity firstly as descriptions (that are for example displayed on a product page) and secondly as simple text files (that can be downloaded on the product page, but are not displayed), ClassMetadataInfo tries to generate joining table called product_textfile for the descriptions field, then tries to generated joining table called product_textfile for the textfiles, but the latter will fail, because the product_textfile table already exists.

      I propose that the table name generation strategy for many to many relations is changed so it will use the actual field name rather than the entity name. In the above example the joining tables would be product_descriptions and product_textFiles. I know that the standard naming conventions for database tables are not to use plurals, but I think it's better to use plurals and have those joining tables created automatically than not use them and have the user set names for the joining tables manually.

      This new behaviour can be achieved by changing the file ClassMetadataInfo.php, line 837 from $targetShortName = substr($mapping['targetEntity'], strrpos($mapping['targetEntity'], '
      ') + 1); to $targetShortName = $mapping['fieldName'];

        Activity

        Hide
        Benjamin Eberlei added a comment -

        This will not be implemented, you can use:

        /**
         * @JoinTable(name="other_name")
         * @ManyToMany(targetEntity="Foo")
         */
        
        Show
        Benjamin Eberlei added a comment - This will not be implemented, you can use: /** * @JoinTable(name= "other_name" ) * @ManyToMany(targetEntity= "Foo" ) */

          People

          • Assignee:
            Roman S. Borschel
            Reporter:
            Petr Motejlek
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: