From b3a6fb7fde9e6c3e3c56f4fe7b9d2e1055de58b4 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Wed, 18 Mar 2015 17:06:30 +0100 Subject: [PATCH] [DDC-3461] Renamed AssocationBuilder::isPrimaryKey() to makePrimaryKey(). Same for FieldBuilder and depreceating isPrimaryKey(). Adjust tests. Revert change in ClassMetadataInfo and fix bug. --- .../ORM/Mapping/Builder/AssociationBuilder.php | 2 +- lib/Doctrine/ORM/Mapping/Builder/FieldBuilder.php | 11 +++++++++++ lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php | 6 +----- .../Tests/ORM/Mapping/ClassMetadataBuilderTest.php | 12 ++++++------ tests/Doctrine/Tests/TestInit.php | 1 + 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/Builder/AssociationBuilder.php b/lib/Doctrine/ORM/Mapping/Builder/AssociationBuilder.php index e2ad52885..5bc75e31e 100644 --- a/lib/Doctrine/ORM/Mapping/Builder/AssociationBuilder.php +++ b/lib/Doctrine/ORM/Mapping/Builder/AssociationBuilder.php @@ -188,7 +188,7 @@ class AssociationBuilder * * @return self */ - public function isPrimaryKey() + public function makePrimaryKey() { $this->mapping['id'] = true; diff --git a/lib/Doctrine/ORM/Mapping/Builder/FieldBuilder.php b/lib/Doctrine/ORM/Mapping/Builder/FieldBuilder.php index 9be19eb40..425840aaf 100644 --- a/lib/Doctrine/ORM/Mapping/Builder/FieldBuilder.php +++ b/lib/Doctrine/ORM/Mapping/Builder/FieldBuilder.php @@ -145,9 +145,20 @@ class FieldBuilder /** * Sets field as primary key. * + * @deprecated Use makePrimaryKey() instead * @return FieldBuilder */ public function isPrimaryKey() + { + return $this->makePrimaryKey(); + } + + /** + * Sets field as primary key. + * + * @return FieldBuilder + */ + public function makePrimaryKey() { $this->mapping['id'] = true; return $this; diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 75760abf4..dd47c9788 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -1462,11 +1462,7 @@ class ClassMetadataInfo implements ClassMetadata } if ( ! in_array($mapping['fieldName'], $this->identifier)) { - if (! isset($mapping['joinColumns'])) { - throw MappingException::illegalInverseIdentifierAssociation($this->name, $mapping['fieldName']); - } - - if (count($mapping['joinColumns']) >= 2) { + if (isset($mapping['joinColumns']) && count($mapping['joinColumns']) >= 2) { throw MappingException::cannotMapCompositePrimaryKeyEntitiesAsForeignId( $mapping['targetEntity'], $this->name, $mapping['fieldName'] ); diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php index 94b830a9a..56bf46ddc 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php @@ -253,7 +253,7 @@ class ClassMetadataBuilderTest extends \Doctrine\Tests\OrmTestCase public function testCreatePrimaryField() { - $this->builder->createField('id', 'integer')->isPrimaryKey()->generatedValue()->build(); + $this->builder->createField('id', 'integer')->makePrimaryKey()->generatedValue()->build(); $this->assertEquals(array('id'), $this->cm->identifier); $this->assertEquals(array('columnName' => 'id', 'fieldName' => 'id', 'id' => true, 'type' => 'integer'), $this->cm->fieldMappings['id']); @@ -341,7 +341,7 @@ class ClassMetadataBuilderTest extends \Doctrine\Tests\OrmTestCase ->addJoinColumn('group_id', 'id', true, false, 'CASCADE') ->cascadeAll() ->fetchExtraLazy() - ->isPrimaryKey() + ->makePrimaryKey() ->build() ); @@ -467,7 +467,7 @@ class ClassMetadataBuilderTest extends \Doctrine\Tests\OrmTestCase ->addJoinColumn('group_id', 'id', true, false, 'CASCADE') ->cascadeAll() ->fetchExtraLazy() - ->isPrimaryKey() + ->makePrimaryKey() ->build() ); @@ -534,7 +534,7 @@ class ClassMetadataBuilderTest extends \Doctrine\Tests\OrmTestCase ->createOneToOne('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') ->mappedBy('test') ->fetchExtraLazy() - ->isPrimaryKey() + ->makePrimaryKey() ->build(); } @@ -626,7 +626,7 @@ class ClassMetadataBuilderTest extends \Doctrine\Tests\OrmTestCase $this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->builder->createManyToMany('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') - ->isPrimaryKey() + ->makePrimaryKey() ->setJoinTable('groups_users') ->addJoinColumn('group_id', 'id', true, false, 'CASCADE') ->addInverseJoinColumn('user_id', 'id') @@ -679,7 +679,7 @@ class ClassMetadataBuilderTest extends \Doctrine\Tests\OrmTestCase $this->setExpectedException('Doctrine\ORM\Mapping\MappingException'); $this->builder->createOneToMany('groups', 'Doctrine\Tests\Models\CMS\CmsGroup') - ->isPrimaryKey() + ->makePrimaryKey() ->mappedBy('test') ->setOrderBy(array('test')) ->setIndexBy('test') diff --git a/tests/Doctrine/Tests/TestInit.php b/tests/Doctrine/Tests/TestInit.php index 1ad733376..1474bab4e 100644 --- a/tests/Doctrine/Tests/TestInit.php +++ b/tests/Doctrine/Tests/TestInit.php @@ -24,3 +24,4 @@ if ( ! file_exists(__DIR__ . '/Proxies') && ! mkdir(__DIR__ . '/Proxies')) { if ( ! file_exists(__DIR__ . '/ORM/Proxy/generated') && ! mkdir(__DIR__ . '/ORM/Proxy/generated')) { throw new \Exception('Could not create ' . __DIR__ . '/ORM/Proxy/generated Folder.'); } +