Dave Bixler Thu Dec 20 16:23:41 -0500 2012

Subject: Help on created_at

Hello there. I've used ActiveRecord for quite a while now, though have not worked with it in about 12 months. I built a project a while back that has been working flawlessly. I've been asked to make a few changes and I have a quick question. Due to the database schema, doing database updates is probably not going to happen. It turns out that it's much easier to just delete the original record and write a new one (it's not a large database). However, I need to preserve the created_at column to what it was originally. Is it possible to override that field on insert? If not, is it possible to insert the record, change the created_at, and then do an update?

I appreciate any help with this that anyone can offer.


Devin Moore Mon Dec 31 10:26:56 -0500 2012

I typically use the following to perform operations immediately before an update/create. The 'before_create' array is used to specify an array of functions to be called immediately before a create into the db.

 1 static $before_create = array("my_create", "my_function");
 3 public function my_create() {
 4     $this->created_time = time();
 5 }
 7 public function my_function() {
 8     $this->updated_time = time();
 9 }