diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 2d6ec7c20..7e18c87f9 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -836,8 +836,17 @@ class ClassMetadataInfo { $mapping = $this->_validateAndCompleteAssociationMapping($mapping); if ($mapping['isOwningSide']) { - $sourceShortName = strtolower(substr($mapping['sourceEntity'], strrpos($mapping['sourceEntity'], '\\') + 1)); - $targetShortName = strtolower(substr($mapping['targetEntity'], strrpos($mapping['targetEntity'], '\\') + 1)); + if (strpos($mapping['sourceEntity'], '\\') !== false) { + $sourceShortName = strtolower(substr($mapping['sourceEntity'], strrpos($mapping['sourceEntity'], '\\') + 1)); + } else { + $sourceShortName = strtolower($mapping['sourceEntity']); + } + if (strpos($mapping['targetEntity'], '\\') !== false) { + $targetShortName = strtolower(substr($mapping['targetEntity'], strrpos($mapping['targetEntity'], '\\') + 1)); + } else { + $targetShortName = strtolower($mapping['targetEntity']); + } + // owning side MUST have a join table if ( ! isset($mapping['joinTable']['name'])) { $mapping['joinTable']['name'] = $sourceShortName .'_' . $targetShortName; diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php index f8425b42f..fc8de1cbb 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php @@ -6,6 +6,7 @@ use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Events; require_once __DIR__ . '/../../TestInit.php'; +require_once __DIR__ . '/../../Models/Global/GlobalNamespaceModel.php'; class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase { @@ -300,4 +301,15 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase $this->setExpectedException('Doctrine\ORM\Mapping\MappingException', "No mapping found for field 'foo' on class 'Doctrine\Tests\Models\CMS\CmsUser'."); $cm->getFieldMapping('foo'); } + + /** + * @group DDC-961 + */ + public function testJoinTableMappingDefaults() + { + $cm = new ClassMetadata('DoctrineGlobal_Article'); + $cm->mapManyToMany(array('fieldName' => 'author', 'targetEntity' => 'Doctrine\Tests\Models\CMS\CmsUser')); + + $this->assertEquals('doctrineglobal_article_cmsuser', $cm->associationMappings['author']['joinTable']['name']); + } } \ No newline at end of file