DDC-759: More than one many-to-many relations cannot be created using default values #5272

doctrinebot opened this Issue Aug 19, 2010 · 2 comments

1 participant


Jira issue originally created by user petr_motejlek:

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 producttextfile for the descriptions field, then tries to generated joining table called product_textfile for the textfiles, but the latter will fail, because the producttextfile 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 productdescriptions and producttextFiles. 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'];


Comment created by @beberlei:

This will not be implemented, you can use:

 * @JoinTable(name="other_name")
 * @ManyToMany(targetEntity="Foo")

Issue was closed with resolution "Invalid"

@doctrinebot doctrinebot added this to the 2.0-RC1 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment