Automatic Time Stamps & Soft Deletes

25 views
Skip to first unread message

Brian Lang

unread,
Feb 7, 2012, 12:13:35 PM2/7/12
to ColdFusion on Wheels
I'm new to CFWheels - started last week. I've managed to get a horse
sale admin site up and running just fine.
Something that's bothering me though: I can't get the Automatic Time
Stamps (http://cfwheels.org/docs/1-1/chapter/automatic-time-stamps) or
Soft Deletes to work.

I've got fields called createdat and modifiedat and deletedat but I'm
not seeing them get updated on creation, update or delete.
I'm using MySQL.
Fields are set as datetime, Allow Null is set, and the default value =
NULL

In my controller, In my edit method, I am calling create()
<cfset horse = model("horse").create(params.horse)>

And in my update method, I am calling update()
<cfset horse.update(params.horse)>

So why am I not seeing the database fields update appropriately?

Here's the table definition:

CREATE TABLE `horses` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`saleid` int(11) DEFAULT '0',
`name` varchar(60) DEFAULT '',
`sire` varchar(60) DEFAULT '',
`dam` varchar(60) DEFAULT '',
`sex` varchar(7) DEFAULT '',
`birthdate` date DEFAULT NULL,
`buyer` varchar(100) DEFAULT '',
`price` decimal(11,2) DEFAULT '0.00',
`createdat` datetime DEFAULT NULL,
`modifiedat` datetime DEFAULT NULL,
`deletedat` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `saleid` (`saleid`),
CONSTRAINT `saleid` FOREIGN KEY (`saleid`) REFERENCES `sales` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=87 DEFAULT CHARSET=utf8
ROW_FORMAT=DYNAMIC;

Per Djurner

unread,
Feb 8, 2012, 6:18:10 PM2/8/12
to cfwh...@googlegroups.com
Looks good to me, did you reload the app after adding those columns so that Wheels can pick up the changes?


--
You received this message because you are subscribed to the Google Groups "ColdFusion on Wheels" group.
To post to this group, send email to cfwh...@googlegroups.com.
To unsubscribe from this group, send email to cfwheels+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cfwheels?hl=en.


Brian Lang

unread,
Feb 8, 2012, 6:46:59 PM2/8/12
to ColdFusion on Wheels
I've reloaded the app, and restarted the (test) server (my mac).

Adam Chapman

unread,
Feb 9, 2012, 4:11:32 PM2/9/12
to ColdFusion on Wheels
Hi Brian,

I believe your modifiedat column should be called updatedat.

Regards,
Adam

Simon Allard

unread,
Feb 9, 2012, 4:28:33 PM2/9/12
to cfwh...@googlegroups.com
Hi Brian,

If you want to use modifiedat instead of updatedat, you can set it like this in your config/settings file.

<cfset set(timeStampOnUpdateProperty="modifiedat")>

A+

Simon

Brian Lang

unread,
Feb 10, 2012, 12:13:16 PM2/10/12
to ColdFusion on Wheels
Ok. So I can't read I guess. Changed it updatedat and now it works.
Surprise!

I knew I could change the TimeStampOnUpdateProperty on a global level.
Does anyone know if you can do that on a per-table basis (ie. in the
Model)??

Thanks guys.




On Feb 9, 1:28 pm, Simon Allard <ellor1...@gmail.com> wrote:
> Hi Brian,
>
> If you want to use modifiedat instead of updatedat, you can set it like
> this in your config/settings file.
>
> <cfset set(timeStampOnUpdateProperty="modifiedat")>
>
> A+
>
> Simon
>

Adam Chapman

unread,
Feb 12, 2012, 5:03:54 PM2/12/12
to ColdFusion on Wheels
You can use the property() function in your model's init method.

<cffunction name="init">
<cfset property(name="updatedat", column="modifiedat")>
</cffunction>
Reply all
Reply to author
Forward
0 new messages