1
0
mirror of synced 2024-12-13 22:56:04 +03:00

DDC-1034 - Fix bug where callbacks where registered multiple times in inheritance hierachies.

This commit is contained in:
Benjamin Eberlei 2011-03-04 23:00:54 +01:00
parent c0d26f2308
commit 67ae22b911
2 changed files with 61 additions and 1 deletions

View File

@ -377,7 +377,8 @@ class AnnotationDriver implements Driver
// Evaluate @HasLifecycleCallbacks annotation
if (isset($classAnnotations['Doctrine\ORM\Mapping\HasLifecycleCallbacks'])) {
foreach ($class->getMethods() as $method) {
if ($method->isPublic()) {
// filter for the declaring class only, callbacks from parents will already be registered.
if ($method->isPublic() && $method->getDeclaringClass()->getName() == $class->name) {
$annotations = $this->_reader->getMethodAnnotations($method);
if (isset($annotations['Doctrine\ORM\Mapping\PrePersist'])) {

View File

@ -167,6 +167,26 @@ class AnnotationDriverTest extends AbstractMappingDriverTest
"superclass 'Doctrine\Tests\ORM\Mapping\MappedSuperClassInheritence'.");
$usingInvalidMsc = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\MappedSuperClassInheritence');
}
/**
* @group DDC-1034
*/
public function testInheritanceSkipsParentLifecycleCallbacks()
{
$annotationDriver = $this->_loadDriver();
$cm = new ClassMetadata('Doctrine\Tests\ORM\Mapping\AnnotationChild');
$em = $this->_getTestEntityManager();
$em->getConfiguration()->setMetadataDriverImpl($annotationDriver);
$factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
$factory->setEntityManager($em);
$cm = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\AnnotationChild');
$this->assertEquals(array("postLoad" => array("postLoad"), "preUpdate" => array("preUpdate")), $cm->lifecycleCallbacks);
$cm = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\AnnotationParent');
$this->assertEquals(array("postLoad" => array("postLoad"), "preUpdate" => array("preUpdate")), $cm->lifecycleCallbacks);
}
}
/**
@ -209,3 +229,42 @@ class MappedSuperClassInheritence
{
}
/**
* @Entity
* @InheritanceType("JOINED")
* @DiscriminatorMap({"parent" = "AnnotationParent", "child" = "AnnotationChild"})
* @HasLifecycleCallbacks
*/
class AnnotationParent
{
/**
* @Id @Column(type="integer") @GeneratedValue
*/
private $id;
/**
* @PostLoad
*/
public function postLoad()
{
}
/**
* @PreUpdate
*/
public function preUpdate()
{
}
}
/**
* @Entity
* @HasLifecycleCallbacks
*/
class AnnotationChild extends AnnotationParent
{
}