Doctrine PrePersist and PreUpdate functions not working

Whilst developing my site, I was finding that my PrePersist (on creation) and PreUpdate (on update) doctrine2 lifecycle callbacks weren't being triggered:

/**
 * @ORM\PrePersist
 */
protected function prePersist()
{
    $this->dateCreated = new \DateTime();
    $this->deleted = false;
}

/**
 * @ORM\PreUpdate
 */
protected function preUpdate()
{
    $this->dateUpdated = new \DateTime();
}

The Solution

PrePersist and PreUpdate function must be public functions in your entities. Changing mine to public functions allowed the lifecycle callbacks to trigger and run.

Comments

Comments have been closed for this post