Any idea why I cannot automatically update creation_time field in my table:
id | name | creation_time
creation_time–>
Type: Timestamp,
Default Value: CURRENT_TIMESTAMP
When I try to save data in cakephp by using a statement like this:
$this->Model->create();
$this->Model->save(array('name'=>'...'));
I got new data inserting to the table but without the creation time. It is abnormal that when i run an insert into Mysql statement then the field is automatically update as current timestamp.
I know that I could use created field as in Cakephp’s documentation but for my case, i don’t want to change the existing field name because it is a table used by other members working in the same project.
Please advise me.
When you call
$this->Model->create(), Cake populates the data contained in$this->Modelwith default values. If you debug$this->Model->dataYou will that the
creation_timeis already set, but with a string:)
So when Cake generates the INSERT query, this one contain the
creation_timefield, withCURRENT_TIMESTAMPas a string:If you want to keep your
creation_timefield in the datatable, to generate a working query you could delete the default value before saving the data: