From 333b9c0b9950fe7b0002b2d0c8017a1affc8e7ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20FRAN=C3=87OIS?= Date: Thu, 18 Jan 2018 12:07:14 +0100 Subject: [PATCH 1/2] Fix #6991: correctly resolve identifer values in ManyToManyPersister --- lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php index 84d5ccfbc..c817f6097 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php @@ -419,7 +419,7 @@ class ManyToManyPersister extends AbstractCollectionPersister foreach ($mapping['relationToSourceKeyColumns'] as $columnName => $refColumnName) { $params[] = isset($sourceClass->fieldNames[$refColumnName]) ? $identifier[$sourceClass->fieldNames[$refColumnName]] - : $identifier[$sourceClass->getFieldForColumn($columnName)]; + : $identifier[$sourceClass->getFieldForColumn($refColumnName)]; } return $params; From 40f2a3efbaab30e466ec9d42132b67e835694e4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20FRAN=C3=87OIS?= Date: Fri, 19 Jan 2018 18:03:46 +0100 Subject: [PATCH 2/2] Add test case for many-to-many collection deletion, when owning side has a composite PK --- .../Models/ManyToManyPersister/ChildClass.php | 52 ++++++++++++++++++ .../ManyToManyPersister/OtherParentClass.php | 23 ++++++++ .../ManyToManyPersister/ParentClass.php | 39 ++++++++++++++ .../Persisters/ManyToManyPersisterTest.php | 53 +++++++++++++++++++ 4 files changed, 167 insertions(+) create mode 100644 tests/Doctrine/Tests/Models/ManyToManyPersister/ChildClass.php create mode 100644 tests/Doctrine/Tests/Models/ManyToManyPersister/OtherParentClass.php create mode 100644 tests/Doctrine/Tests/Models/ManyToManyPersister/ParentClass.php create mode 100644 tests/Doctrine/Tests/ORM/Persisters/ManyToManyPersisterTest.php diff --git a/tests/Doctrine/Tests/Models/ManyToManyPersister/ChildClass.php b/tests/Doctrine/Tests/Models/ManyToManyPersister/ChildClass.php new file mode 100644 index 000000000..d3b9b16c1 --- /dev/null +++ b/tests/Doctrine/Tests/Models/ManyToManyPersister/ChildClass.php @@ -0,0 +1,52 @@ +id1 = $id1; + $this->otherParent = $otherParent; + $this->parents = new ArrayCollection(); + } +} diff --git a/tests/Doctrine/Tests/Models/ManyToManyPersister/OtherParentClass.php b/tests/Doctrine/Tests/Models/ManyToManyPersister/OtherParentClass.php new file mode 100644 index 000000000..04e27e616 --- /dev/null +++ b/tests/Doctrine/Tests/Models/ManyToManyPersister/OtherParentClass.php @@ -0,0 +1,23 @@ +id = $id; + } +} diff --git a/tests/Doctrine/Tests/Models/ManyToManyPersister/ParentClass.php b/tests/Doctrine/Tests/Models/ManyToManyPersister/ParentClass.php new file mode 100644 index 000000000..3007a1013 --- /dev/null +++ b/tests/Doctrine/Tests/Models/ManyToManyPersister/ParentClass.php @@ -0,0 +1,39 @@ +id = $id; + $this->children = new ArrayCollection(); + } +} diff --git a/tests/Doctrine/Tests/ORM/Persisters/ManyToManyPersisterTest.php b/tests/Doctrine/Tests/ORM/Persisters/ManyToManyPersisterTest.php new file mode 100644 index 000000000..989fc8493 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Persisters/ManyToManyPersisterTest.php @@ -0,0 +1,53 @@ +children->add($child); + $child->parents->add($parent); + + $em = $this->_getTestEntityManager(); + $em->persist($parent); + $em->flush(); + + /** @var ChildClass|null $childReloaded */ + $childReloaded = $em->find(ChildClass::class, ['id1' => 1, 'otherParent' => $otherParent]); + + self::assertNotNull($childReloaded); + + $persister = new ManyToManyPersister($em); + $persister->delete($childReloaded->parents); + + /** @var ConnectionMock $conn */ + $conn = $em->getConnection(); + + $updates = $conn->getExecuteUpdates(); + $lastUpdate = array_pop($updates); + + self::assertEquals('DELETE FROM parent_child WHERE child_id1 = ? AND child_id2 = ?', $lastUpdate['query']); + self::assertEquals([1, 42], $lastUpdate['params']); + } +}