Merge branch 'DDC-945'
This commit is contained in:
commit
26bb7978b5
@ -382,6 +382,9 @@ class ClassMetadataFactory
|
|||||||
{
|
{
|
||||||
foreach ($parentClass->associationMappings as $field => $mapping) {
|
foreach ($parentClass->associationMappings as $field => $mapping) {
|
||||||
if ($parentClass->isMappedSuperclass) {
|
if ($parentClass->isMappedSuperclass) {
|
||||||
|
if ($mapping['type'] & ClassMetadata::TO_MANY) {
|
||||||
|
throw MappingException::illegalToManyAssocationOnMappedSuperclass($parentClass->name, $field);
|
||||||
|
}
|
||||||
$mapping['sourceEntity'] = $subClass->name;
|
$mapping['sourceEntity'] = $subClass->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.");
|
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."'.");
|
||||||
|
}
|
||||||
}
|
}
|
@ -125,14 +125,30 @@ class AnnotationDriverTest extends AbstractMappingDriverTest
|
|||||||
$factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
|
$factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
|
||||||
$factory->setEntityManager($em);
|
$factory->setEntityManager($em);
|
||||||
|
|
||||||
$classPage = new ClassMetadata('Doctrine\Tests\Models\DirectoryTree\File');
|
|
||||||
$classPage = $factory->getMetadataFor('Doctrine\Tests\Models\DirectoryTree\File');
|
$classPage = $factory->getMetadataFor('Doctrine\Tests\Models\DirectoryTree\File');
|
||||||
$this->assertEquals('Doctrine\Tests\Models\DirectoryTree\File', $classPage->associationMappings['parentDirectory']['sourceEntity']);
|
$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');
|
$classDirectory = $factory->getMetadataFor('Doctrine\Tests\Models\DirectoryTree\Directory');
|
||||||
$this->assertEquals('Doctrine\Tests\Models\DirectoryTree\Directory', $classDirectory->associationMappings['parentDirectory']['sourceEntity']);
|
$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 */
|
/** @Id @Column */
|
||||||
public $id;
|
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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user