diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index e4b1f050a..53037d1ee 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -515,9 +515,8 @@ class YamlDriver extends FileDriver if ( ! isset($joinColumnElement['name'])) { $joinColumnElement['name'] = $joinColumnName; } + $joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumnElement); } - - $joinTable['joinColumns'][] = $this->joinColumnToArray($joinColumnElement); } if (isset($joinTableElement['inverseJoinColumns'])) { @@ -525,9 +524,8 @@ class YamlDriver extends FileDriver if ( ! isset($joinColumnElement['name'])) { $joinColumnElement['name'] = $joinColumnName; } + $joinTable['inverseJoinColumns'][] = $this->joinColumnToArray($joinColumnElement); } - - $joinTable['inverseJoinColumns'][] = $this->joinColumnToArray($joinColumnElement); } $mapping['joinTable'] = $joinTable; diff --git a/tests/Doctrine/Tests/Models/DDC3711/DDC3711EntityA.php b/tests/Doctrine/Tests/Models/DDC3711/DDC3711EntityA.php new file mode 100644 index 000000000..3146969ed --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC3711/DDC3711EntityA.php @@ -0,0 +1,78 @@ + + */ +namespace Doctrine\Tests\Models\DDC3711; + +use Doctrine\Common\Collections\ArrayCollection; + +class DDC3711EntityA +{ + /** + * @var int + */ + private $id1; + + /** + * @var int + */ + private $id2; + + /** + * @var ArrayCollection + */ + private $entityB; + + /** + * @return mixed + */ + public function getId1() + { + return $this->id1; + } + + /** + * @param mixed $id1 + */ + public function setId1($id1) + { + $this->id1 = $id1; + } + + /** + * @return mixed + */ + public function getId2() + { + return $this->id2; + } + + /** + * @param mixed $id2 + */ + public function setId2($id2) + { + $this->id2 = $id2; + } + + /** + * @return ArrayCollection + */ + public function getEntityB() + { + return $this->entityB; + } + + /** + * @param ArrayCollection $entityB + * + * @return DDC3711EntityA + */ + public function addEntityB($entityB) + { + $this->entityB[] = $entityB; + + return $this; + } +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/Models/DDC3711/DDC3711EntityB.php b/tests/Doctrine/Tests/Models/DDC3711/DDC3711EntityB.php new file mode 100644 index 000000000..ff589e092 --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC3711/DDC3711EntityB.php @@ -0,0 +1,75 @@ + + */ +namespace Doctrine\Tests\Models\DDC3711; + +use Doctrine\Common\Collections\ArrayCollection; + +class DDC3711EntityB +{ + /** + * @var int + */ + private $id1; + + /** + * @var int + */ + private $id2; + + /** + * @var ArrayCollection + */ + private $entityA; + + /** + * @return int + */ + public function getId1() + { + return $this->id1; + } + + /** + * @param int $id1 + */ + public function setId1($id1) + { + $this->id1 = $id1; + } + + /** + * @return int + */ + public function getId2() + { + return $this->id2; + } + + /** + * @param int $id2 + */ + public function setId2($id2) + { + $this->id2 = $id2; + } + + /** + * @return ArrayCollection + */ + public function getEntityA() + { + return $this->entityA; + } + + /** + * @param ArrayCollection $entityA + */ + public function addEntityA($entityA) + { + $this->entityA[] = $entityA; + } + +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3711Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3711Test.php new file mode 100644 index 000000000..52c96154f --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3711Test.php @@ -0,0 +1,30 @@ + + */ + +namespace Doctrine\Tests\ORM\Functional\Ticket; + + +use Doctrine\ORM\Mapping\ClassMetadata; +use Doctrine\Tests\ORM\Mapping\YamlMappingDriverTest; + +class DDC3711Test extends YamlMappingDriverTest +{ + public function testCompositeKeyForJoinTableInManyToManyCreation() + { + $yamlDriver = $this->_loadDriver(); + + $em = $this->_getTestEntityManager(); + $em->getConfiguration()->setMetadataDriverImpl($yamlDriver); + $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory(); + $factory->setEntityManager($em); + + $entityA = new ClassMetadata('Doctrine\Tests\Models\DDC3711\DDC3711EntityA'); + $entityA = $factory->getMetadataFor('Doctrine\Tests\Models\DDC3711\DDC3711EntityA'); + + $this->assertEquals(array('link_a_id1' => "id1", 'link_a_id2' => "id2"), $entityA->associationMappings['entityB']['relationToSourceKeyColumns']); + $this->assertEquals(array('link_b_id1' => "id1", 'link_b_id2' => "id2"), $entityA->associationMappings['entityB']['relationToTargetKeyColumns']); + + } +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC3711.DDC3711EntityA.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC3711.DDC3711EntityA.dcm.yml new file mode 100644 index 000000000..c8a87331d --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC3711.DDC3711EntityA.dcm.yml @@ -0,0 +1,23 @@ +Doctrine\Tests\Models\DDC3711\DDC3711EntityA: + type: entity + table: ddc3711.entityA + id: + id1: + type: int + id2: + type: int + manyToMany: + entityB: + targetEntity: Doctrine\Tests\Models\DDC3711\DDC3711EntityB + joinTable: + name: link + joinColumns: + link_a_id1: + referencedColumnName: id1 + link_a_id2: + referencedColumnName: id2 + inverseJoinColumns: + link_b_id1: + referencedColumnName: id1 + link_b_id2: + referencedColumnName: id2 \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC3711.DDC3711EntityB.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC3711.DDC3711EntityB.dcm.yml new file mode 100644 index 000000000..24ec96932 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.Models.DDC3711.DDC3711EntityB.dcm.yml @@ -0,0 +1,8 @@ +Doctrine\Tests\Models\DDC3711\DDC3711EntityB: + type: entity + table: ddc3711.entityB + id: + id1: + type: int + id2: + type: int