DDC-2895: [GH-902] Fix Lifecycle Callbacks #3610

Closed
opened 2026-01-22 14:23:42 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Jan 8, 2014).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user @doctrinebot:

This issue is created automatically through a Github pull request on behalf of gwagner:

Url: https://github.com/doctrine/doctrine2/pull/902

Message:

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.

Originally created by @doctrinebot on GitHub (Jan 8, 2014). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user @doctrinebot: This issue is created automatically through a Github pull request on behalf of gwagner: Url: https://github.com/doctrine/doctrine2/pull/902 Message: 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.
admin added the Bug label 2026-01-22 14:23:42 +01:00
admin closed this issue 2026-01-22 14:23:43 +01:00
Author
Owner

@doctrinebot commented on GitHub (Feb 8, 2014):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-902] was closed:
https://github.com/doctrine/doctrine2/pull/902

@doctrinebot commented on GitHub (Feb 8, 2014): Comment created by @doctrinebot: A related Github Pull-Request [GH-902] was closed: https://github.com/doctrine/doctrine2/pull/902
Author
Owner

@doctrinebot commented on GitHub (Feb 8, 2014):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Feb 8, 2014): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3610