[solved] beforeSave()

Hi guys,

i want to perform a function in my model beforeSave(), but only if it is a new record, not on update.

In doctrine i have different hooks (preInsert, preSave, preUpdate …) - is there anything similar in the active record class? I had a look in the API but couldn’t find.

If not, how can i distinguish insert / update of the record?



There is this - http://www.yiiframework.com/doc/api/1.1/CActiveRecord#isNewRecord-detail

Ah, so obvious.



And while you’re on that page, also check the protected before*() / after*() methods. You can override them as alternative to he hooks you mentioned.