[PR #902] [MERGED] Fix Lifecycle Callbacks #8866

Open
opened 2026-01-22 16:02:04 +01:00 by admin · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/doctrine/orm/pull/902
Author: @gwagner
Created: 1/8/2014
Status: Merged
Merged: 2/8/2014
Merged by: @beberlei

Base: masterHead: master


📝 Commits (4)

📊 Changes

3 files changed (+117 additions, -4 deletions)

View changed files

📝 lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php (+4 -0)
📝 lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php (+1 -4)
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2895Test.php (+112 -0)

📄 Description

Remove a bit of code that breaks lifecycle callbacks of parent MappedSuperclasses

Lets say we are working with this code:

/**
 * @MappedSuperclass
 */
abstract class BaseClass
{
    /**
     * @ORM\Column(name="last_modified", type="datetimetz", nullable=false)
     * @var \DateTime
     */
    protected $lastModified;

    /**
     * @ORM\PrePersist
     * @ORM\PreUpdate
     */
    public function setLastModifiedPreUpdate()
    {
        $this->setLastModified(new \DateTime());
    }

    /**
     * @param \DateTime $lastModified
     */
    public function setLastModified( $lastModified )
    {
        $this->lastModified = $lastModified;
    }

    /**
     * @return \DateTime
     */
    public function getLastModified()
    {
        return $this->lastModified;
    }
}

/**
 * Class MyClass
 *
 * @Entity
 * @HasLifecycleCallbacks
 */
class MyClass extends BaseClass
{
    // Whatever you want in here
}

And you want to save MyClass and have it call the Lifecycle callbacks for your BaseClass. If you leave things they way they are programmed today, the BaseClass will never get its callbacks registered.

By removing the little bit of code there [Lines 472-475], you now get lifecycle callbacks through the entire stack, not just the top most class.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/doctrine/orm/pull/902 **Author:** [@gwagner](https://github.com/gwagner) **Created:** 1/8/2014 **Status:** ✅ Merged **Merged:** 2/8/2014 **Merged by:** [@beberlei](https://github.com/beberlei) **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (4) - [`db31c58`](https://github.com/doctrine/orm/commit/db31c5810209de5c381a8b4cfe0767832f5f9726) Fix Lifecycle Callbacks - [`4772cbf`](https://github.com/doctrine/orm/commit/4772cbfae6364637911dd0ab8cea49c15faba03a) Add a test - [`e9739f8`](https://github.com/doctrine/orm/commit/e9739f85911060a5789336af5efc7e328c8a5bea) Fix some code standard things - [`b863b9b`](https://github.com/doctrine/orm/commit/b863b9b95712bab7dc997c18f62d4c4dc0ee9676) Fix some code standard things ### 📊 Changes **3 files changed** (+117 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php` (+4 -0) 📝 `lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php` (+1 -4) ➕ `tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2895Test.php` (+112 -0) </details> ### 📄 Description Remove a bit of code that breaks lifecycle callbacks of parent MappedSuperclasses Lets say we are working with this code: ``` php /** * @MappedSuperclass */ abstract class BaseClass { /** * @ORM\Column(name="last_modified", type="datetimetz", nullable=false) * @var \DateTime */ protected $lastModified; /** * @ORM\PrePersist * @ORM\PreUpdate */ public function setLastModifiedPreUpdate() { $this->setLastModified(new \DateTime()); } /** * @param \DateTime $lastModified */ public function setLastModified( $lastModified ) { $this->lastModified = $lastModified; } /** * @return \DateTime */ public function getLastModified() { return $this->lastModified; } } /** * Class MyClass * * @Entity * @HasLifecycleCallbacks */ class MyClass extends BaseClass { // Whatever you want in here } ``` And you want to save MyClass and have it call the Lifecycle callbacks for your BaseClass. If you leave things they way they are programmed today, the BaseClass will never get its callbacks registered. By removing the little bit of code there [Lines 472-475], you now get lifecycle callbacks through the entire stack, not just the top most class. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
admin added the pull-request label 2026-01-22 16:02:04 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#8866