I have Doctrine timestampable set for my symfony doctrine and other entities are handling this as they should but one is not not setting any date at all.
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Digital\UserBundle\Entity\User;
/**
* ChallengeScore
*
* @ORM\Table(name="app_challenges_scores")
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap({"race" = "Digital\ApplicationBundle\Entity\Race\ChallengeScore", "individual" = "ChallengeScore"})
* @ORM\Entity(repositoryClass="Digital\ApplicationBundle\EntityRepository\ChallengeScoreRepository")
*/
class ChallengeScore
/**
* @var \DateTime
*
* @ORM\Column(name="date_added", type="datetime")
* @Gedmo\Timestampable(on="create")
*/
private $date_added;
/**
* @var \DateTime
*
* @ORM\Column(name="date_modified", type="datetime")
* @Gedmo\Timestampable(on="update")
*/
private $date_modified;
/**
* Set date_added
*
* @param \DateTime $dateAdded
*
* @return self
*/
public function setDateAdded($dateAdded)
{
$this->date_added = $dateAdded;
return $this;
}
/**
* Get date_added
*
* @return \DateTime
*/
public function getDateAdded()
{
return $this->date_added;
}
/**
* Set date_modified
*
* @param \DateTime $dateModified
*
* @return self
*/
public function setDateModified($dateModified)
{
$this->date_modified = $dateModified;
return $this;
}
/**
* Get date_modified
*
* @return \DateTime
*/
public function getDateModified()
{
return $this->date_modified;
}
}
I was thinking maybe there is an issue with this configuration having inheritance defined... Can anyone spot a problem?
No errors just 00000 persisted to db (so nothing)
Don't forget to add the following to your app/config/services.yml:
services:
gedmo.listener.timestampable:
class: Gedmo\Timestampable\TimestampableListener
tags:
- { name: doctrine.event_subscriber, connection: default }
calls:
- [ setAnnotationReader, [ '@annotation_reader' ] ]
What this basically does is it "listens" if an event is triggered to update/create an entity in your database and it will set the dates.
I hope this solved the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With