I am on Symfony 4, and I have a problem with Lifecycle callbacks. I have two classes, one model and a child of this model. I would like that every child of the model have the same PrePersist callback but the callback is not triggered. Is it normal or did I do something wrong ?
<?php
// src/Models/QuestionModel.php
namespace App\Models;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ODM\MappedSuperclass
* @ODM\HasLifecycleCallbacks
*/
class QuestionModel
{
/**
* @ODM\Id(strategy="AUTO")
*/
protected $id;
/**
* @ODM\Field(type="date")
*/
protected $createdAt;
/**
* @ODM\PrePersist
*/
public function setCreatedAtValue() {
$this->createdAt = new \DateTime();
}
and the child:
<?php
// src/Document/CDN/Question.php
namespace App\Document\CDN;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use App\Models\QuestionModel;
/**
* @ODM\Document(collection="CDNQuestion")
* @ODM\HasLifecycleCallbacks
*/
class Question extends QuestionModel
{
}
If it is normal that it does not work, do you have a solution for my problem ?
Thx