Activerecord Timestamps

Hi all,

I’d like to make a suggestions as per the handling of created_at and updated_at timestamp fields by ActiveRecord. Wouldn’t it be great if AR can handle the updating of these fields automatically given that the columns exists in a db table. You woulnd’t have to override the beforeSave() and set the values yourself, or you could still do that based on decorating a model with

public static $timestamps = true;

value. Also, what if the updating of related models bubble the inheritance chain and touch those timestamps as well. So given a users has many orders. A user creates or updates an order, the order’s created_at and/or updated_at timestamps gets set by AR, but also the updated_at timestamp of User gets set. Again, this can be conditionally applied by an attribute decoration on User or relating models like:

public static $touch = true;



@samdark’s answer is not really a strong argument against adding support for timestamps. Great frameworks like Rails and Laravel has built in support for it in their ORMs, and as far as I know, both Qiang and Taylor Otwell adopted ideas from RoR into their Yii and Laravel.

It just seems natural to have the ORM do this behind the scenes.