I use two doctrine concepts in my model:
- Class Inheritance
- Lifecycle Callbacks
When I load an inherited instance of the parent class, the parent property that is updated with the lifecycle callback is incorrect, well, not the value that I have in the parent classes table of my database.
Parent class: User
use DateTime;
abstract class User implements AdvancedUserInterface, Serializable
{
protected $id;
protected $createdAt;
protected $updatedAt;
public function __construct()
{
$this->createdAt = new DateTime();
$this->updatedAt = new DateTime();
return $this;
}
public function onPreUpdate()
{
$this->updatedAt = new DateTime();
}
}
Child Class: Member
class Member extends User
{
public function __construct()
{
parent::__construct();
return $this;
}
}
Then in the controller
use MyProject\CoreBundle\Entity\Member;
public function someAction(Member $member)
{
$em = $this->getDoctrine()->getManager();
$member = $em->getRepository(Member::class)->find(1);
exit(var_dump($member->getUpdatedAt()));
}
Here is an excerpt from my database contents
// users
|
| id | created_at | updated_at | entity_name |
|
| 1 | 2016-01-01 00:00:00 | 2016-06-01 12:00:00 | member |
|
// members
|
| id |
|
| 1 |
|
When I debug my updatedAt property of my member, I expect the value to be a DateTime object that matches 2016-06-01 12:00:00, not the date of the day ...
Is it even related to loading inheritance? I canโt understand where they came from.