I want to make fields updated_at
and created_at
in my Doctrine entities to update automatically.
In Ruby on Rails models there
The most convinient solution for me is Timestampable
feature of StofDoctrineExtensionsBundle.
Simple configuration and later you are able to make fields createdAt
and updatedAt
of Entity
filled out automatically by adding two simple annotations
like:
@Gedmo\Mapping\Annotation\Timestampable(on="create")
and/or
@Gedmo\Mapping\Annotation\Timestampable(on="update")
e.g.
/**
* @var \DateTime
* @Gedmo\Mapping\Annotation\Timestampable(on="create")
* @Doctrine\ORM\Mapping\Column(type="datetime")
*/
protected $createdAt;
/**
* @var \DateTime
* @Gedmo\Mapping\Annotation\Timestampable(on="update")
* @Doctrine\ORM\Mapping\Column(type="datetime")
*/
protected $updatedAt;
Without any redundant code in pure PHP
.