I've got two little questions:
actAs: { Timestampable: ~ }
What the "~" what mean in the code above?
Then, I've seen that tables with actAs: { Timestampable: ~ }
have two fields (created_at and updated_at).
Is it possible to bind the updated_at field to a particular field (I update this field, then updated_at get a new value) ?
The "~" means that you will use default values or default configuration. In your case, the behavior Timestampable, will use the default value and configuration. So you don't have to redefine them.
From the doc, here are some configuration:
Timestampable:
created:
name: created_at
type: timestamp
format: Y-m-d H:i:s
updated:
disabled: true
You will also find this "~" (a lot) in the default generator.yml
. This way, the generator, even empty, will generate a nice admin:
config:
actions: ~
fields: ~
list: ~
filter: ~
form: ~
edit: ~
new: ~
For your second question, the goal of the Timestampable
is for each modification on a row, the field updated_at
will be set with the current date. So you don't need to take care of it.
Edit:
And if you want to manually update the updated_at
field:
The easiest way is to extends the preSave
function of your model and do the job here. Like:
class Article extends BaseArticle
{
public function preSave($event)
{
if(array_key_exists("your_field", $this->getModified())
{
$this->setUpdatedAt(time());
}
}
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