Hi all,
I am working with an ActiveRecord that I would like to update it’s timestamp value in a certain situation. The best way I found to do this was to create a scenario, and add this rule for that scenario
class item extends CActiveRecord
{
...
return array(
...
array('removed','default','value'=>new CDbExpression('NOW()'),'setOnEmpty'=>false,'on'=>'delete'),
...
);
...
}
class ItemController extends CController
{
...
public function actionDelete($id)
{
$model = $this->loadModel($id);
$model->scenario = 'delete';
if( $model->save() )
echo CJSON::encode( $model->attributes );
}
...
}
So now the value for ‘removed’ when I echo the attributes for the model is as follows
{
...
"removed": {
"expression": "NOW()",
"params": []
},
...
}
But then on further requests for the object the time stamp value is indeed correct.
{
...
"removed": "2013-07-15 17:34:40",
...
}
So really this problem is easily fixed by doing a second look up on the object. However, it would be nice if the actual attributes for the model were consistent with the CDbExpression action.
Thoughts?