Normally , when I update any field in the table (lets say by hand or via plain php code) , the Timestamp field gets automatically updated.This is normal MySQL behavior.
Although , when a model gets saved via Yii ( $model->save() ) the specific Timestamp field doesn’t get updated.
Is the model->save() action not just a simple mysql update action ?
Don’t really know the answer to your question exactly however, I use a before save function in my model and don’t ever have a problem.
Note if you you used gii initially then you and added some fields later for some reason it doesn’t register the new fields as safe even if you use gii to save over the current model. So make sure they are marked as safe like:
ie.
public function rules()
{
return array(
array('creator, create_date, updater, update_date', 'safe'),
);
}
Here is something similar to what i use in my before save in my models
public function beforeSave()
{
if ($this->getIsNewRecord())
{
$this->create_date = new CDbExpression('NOW()');
if (!Yii::app()->user->isGuest) {
$this->creator = Yii::app()->user->name;
}
else {
$this->creator = 'Guest';
}
}
else {
$this->update_date = new CDbExpression('NOW()');
$this->updater = Yii::app()->user->name;
}
return parent::beforeSave();
}
I don’t have those fields on my forms just let the above do it