1
0
mirror of synced 2024-12-14 07:06:04 +03:00

DDC-945 - Throw exception in ClassMetadataFactory when mapped superclass has to many associations.

This commit is contained in:
Benjamin Eberlei 2010-12-28 11:59:51 +01:00
parent 1720527f81
commit aa6ac3d6b0
3 changed files with 47 additions and 2 deletions

View File

@ -382,6 +382,9 @@ class ClassMetadataFactory
{
foreach ($parentClass->associationMappings as $field => $mapping) {
if ($parentClass->isMappedSuperclass) {
if ($mapping['type'] & ClassMetadata::TO_MANY) {
throw MappingException::illegalToManyAssocationOnMappedSuperclass($parentClass->name, $field);
}
$mapping['sourceEntity'] = $subClass->name;
}

View File

@ -227,4 +227,8 @@ class MappingException extends \Doctrine\ORM\ORMException
return new self("Duplicate definition of column '".$columnName."' on entity '".$className."' in a field or discriminator column mapping.");
}
public static function illegalToManyAssocationOnMappedSuperclass($className, $field)
{
return new self("It is illegal to put a one-to-many or many-to-many association on mapped superclass '".$className."#".$field."'.");
}
}

View File

@ -125,14 +125,30 @@ class AnnotationDriverTest extends AbstractMappingDriverTest
$factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
$factory->setEntityManager($em);
$classPage = new ClassMetadata('Doctrine\Tests\Models\DirectoryTree\File');
$classPage = $factory->getMetadataFor('Doctrine\Tests\Models\DirectoryTree\File');
$this->assertEquals('Doctrine\Tests\Models\DirectoryTree\File', $classPage->associationMappings['parentDirectory']['sourceEntity']);
$classDirectory = new ClassMetadata('Doctrine\Tests\Models\DirectoryTree\Directory');
$classDirectory = $factory->getMetadataFor('Doctrine\Tests\Models\DirectoryTree\Directory');
$this->assertEquals('Doctrine\Tests\Models\DirectoryTree\Directory', $classDirectory->associationMappings['parentDirectory']['sourceEntity']);
}
/**
* @group DDC-945
*/
public function testInvalidMappedSuperClassWithManyToManyAssociation()
{
$annotationDriver = $this->_loadDriver();
$em = $this->_getTestEntityManager();
$em->getConfiguration()->setMetadataDriverImpl($annotationDriver);
$factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
$factory->setEntityManager($em);
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException',
"It is illegal to put a one-to-many or many-to-many association on ".
"mapped superclass 'Doctrine\Tests\ORM\Mapping\InvalidMappedSuperClass#users'");
$usingInvalidMsc = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\UsingInvalidMappedSuperClass');
}
}
/**
@ -143,3 +159,25 @@ class ColumnWithoutType
/** @Id @Column */
public $id;
}
/**
* @MappedSuperclass
*/
class InvalidMappedSuperClass
{
/**
* @ManyToMany(targetEntity="Doctrine\Tests\Models\CMS\CmsUser")
*/
private $users;
}
/**
* @Entity
*/
class UsingInvalidMappedSuperClass extends InvalidMappedSuperClass
{
/**
* @Id @Column(type="integer") @GeneratedValue
*/
private $id;
}