Bug #33397

Difference for ManyToMany with JoinTable annotation and without

Added by Christian Müller over 9 years ago. Updated about 9 years ago.

Status:
Resolved
Priority:
Should have
Category:
Persistence
Start date:
2012-01-23
Due date:
% Done:

100%

Estimated time:
PHP Version:
Has patch:
No
Complexity:

Description

There is a difference between joinColumn creation with JoinTable annotation and without for ManyToMany relations. In case there is a JoinTable annotation (and no options for columns are set) the automatic creation inverses the columns so the join works but the columns are named wrong / used wrong.

So if you join class A and Class B the resulting join table will have columns for A identifier and B identifier but the inserted identifiers are exactly the opposite. This does not happen if the JoinTable Annotation is dropped completely.

Thanks to Kira Backes for noticing.

The fix is simple but probably a breaking change.

#1

Updated by Gerrit Code Review over 9 years ago

  • Status changed from New to Under Review

Patch set 2 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/8656

#2

Updated by Gerrit Code Review over 9 years ago

Patch set 3 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/8656

#3

Updated by Karsten Dambekalns over 9 years ago

  • Category set to Persistence
  • Assignee set to Christian Müller

Thanks, I'll check.

#4

Updated by Adrian Föder over 9 years ago

Just was affected by this one by myself; I have

    /**
     * @var \Doctrine\Common\Collections\Collection<\Acme\Rating\Domain\Model\Rating>
     * @ORM\ManyToMany
     * @ORM\JoinTable(inverseJoinColumns={@ORM\JoinColumn(unique=true)})
     */
    protected $ratings;

in order to achieve a OneToMany relation like described at Doctrine;
the resulting CREATE TABLE looks like

CREATE TABLE `acme_acme_domain_model_product_ratings_join` (
  `rating_rating` varchar(40) NOT NULL,
  `acme_product` varchar(40) NOT NULL,
  PRIMARY KEY (`rating_rating`,`acme_product`),
  UNIQUE KEY `UNIQ_DE76D5E47F43B426` (`acme_product`),
  KEY `IDX_DE76D5E4F77B4CAA` (`rating_rating`),
  CONSTRAINT `FK_DE76D5E47F43B426` FOREIGN KEY (`acme_product`) REFERENCES `acme_rating_domain_model_rating` (`flow3_persistence_identifier`),
  CONSTRAINT `FK_DE76D5E4F77B4CAA` FOREIGN KEY (`rating_rating`) REFERENCES `acme_acme_domain_model_product` (`flow3_persistence_identifier`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8$$

#5

Updated by Gerrit Code Review over 9 years ago

Patch set 4 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/8656

#6

Updated by Karsten Dambekalns over 9 years ago

  • Target version set to 1.1
#7

Updated by Karsten Dambekalns over 9 years ago

  • Assignee changed from Christian Müller to Karsten Dambekalns
#8

Updated by Karsten Dambekalns over 9 years ago

  • Target version changed from 1.1 to 1.1 RC1
#9

Updated by Karsten Dambekalns over 9 years ago

  • Target version changed from 1.1 RC1 to 2.0 beta 1
#10

Updated by Gerrit Code Review about 9 years ago

Patch set 1 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/14141

#11

Updated by Gerrit Code Review about 9 years ago

Patch set 2 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/14141

#12

Updated by Gerrit Code Review about 9 years ago

Patch set 3 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/14141

#13

Updated by Gerrit Code Review about 9 years ago

Patch set 4 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/14141

#14

Updated by Gerrit Code Review about 9 years ago

Patch set 5 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/14141

#15

Updated by Gerrit Code Review about 9 years ago

Patch set 6 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/14141

#16

Updated by Christian Müller about 9 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

Also available in: Atom PDF