From aa5df1dbacc0e64c32c5dab7fbed70459c5ddae8 Mon Sep 17 00:00:00 2001 From: Aaron Muylaert Date: Sat, 14 Dec 2013 15:59:10 +0100 Subject: [PATCH 1/2] Create failing test for DDC-2645. Merge not dealing correctly with composite primary keys. --- .../ORM/Functional/Ticket/DDC2645Test.php | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2645Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2645Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2645Test.php new file mode 100644 index 000000000..0c2ea6d0a --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2645Test.php @@ -0,0 +1,55 @@ +id = 123; + + $foo = new DDC2645Foo(1, $bar, 'Foo'); + $foo2 = new DDC2645Foo(1, $bar, 'Bar'); + + $this->_em->persist($bar); + $this->_em->persist($foo); + + $foo3 = $this->_em->merge($foo2); + + $this->assertSame($foo, $foo3); + $this->assertEquals('Bar', $foo->name); + } +} + +/** @Entity */ +class DDC2645Foo +{ + /** @Id @Column(type="integer") */ + private $id; + + /** @Id @ManyToOne(targetEntity="DDC2645Bar") */ + private $bar; + + /** @Column */ + public $name; + + public function __construct($id, $bar, $name) + { + $this->id = $id; + $this->bar = $bar; + $this->name = $name; + } +} + +/** @Entity */ +class DDC2645Bar +{ + /** @Id @Column(type="integer") @GeneratedValue(strategy="NONE") */ + public $id; +} From a5b7069fd7763ef46e4de52afcd09c7718de7c14 Mon Sep 17 00:00:00 2001 From: Pouyan Savoli Date: Sun, 15 Dec 2013 23:31:35 +0100 Subject: [PATCH 2/2] [DDC-2645] Apply patch to fix issue --- lib/Doctrine/ORM/UnitOfWork.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index d00a87af7..ecc2268e7 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1735,6 +1735,8 @@ class UnitOfWork implements PropertyChangedListener $associatedId = $this->getEntityIdentifier($idValue); $flatId[$idField] = $associatedId[$targetClassMetadata->identifier[0]]; + } else { + $flatId[$idField] = $idValue; } }