jacmoe, on 22 April 2013 - 02:29 PM, said:
That behavior does indeed use the beforeSave function. Think of it as reusable code.
That explains something that is (should be) obvious to me: Behaviors are reusable, so I can use one to many models, while using beforeSave()
or any similar is not reusable, so I have to duplicate code for each model (or use a common function, which is nothing else than just another form of behavior-reusable code).
But, your answer doesn't explain, if (and why -- if yes) using CTimestampBehavior is better than using MySQL feature of "ON UPDATE current_timestamp"?
Using behavior here is certainly better, if you plan a database migration or want to develop flexible application, that will be open for virtually any RDBMS. As other database system, other than MySQL, may not have this feature or may it have implemented different way. In such situation, after database migration you would have to manually update / change this part of code, while using behavior would save you from doing that.
Is that the only reason (did I answer myself? :]) or is there something else behind using CTimestampBehavior instead of MySQL feature of "ON UPDATE current_timestamp"?