Another stupid newbie question: How to save only if any safe attributes are changed?

I am trying to update a record with a few user maintainable fields as well as some fields (creation & update timestamps and created_by & updated_by fields) that are set programmatically.

Yii’s default behavior is to resave the record and reset the update timestamp and the updated_by fields whenever the “Save” button is clicked even if none of the user enterable fields have been modified.

I wish to change this behavior. I can think of many ways to do so, but I am wondering what the preferred method would be among more experienced yii programmers.

Thank you very much for having mercy on me.

If you want this behavior (save only when changed) you’ll have to develop it yourself.

You have to extend CActiveRecord and develop this lightweight solution:

add a flag-property like $_changed.

Override function __set($name,$value) and check if the property to set is a database field. If so, set $_changed to true.

Override function save() and call parent::save(). If it returns true, set $_changed to false.