Set Now() to new records

0 views
Skip to first unread message

Chuck Savage

unread,
Dec 17, 2009, 6:08:01 PM12/17/09
to Reactor
I'm doing this in my UserRecord.cfc

<cffunction name="setdateAdded" hint="I set the dateAdded value ."
access="public" output="false" returntype="void">
<cfargument name="dateAdded" hint="I am this record's dateAdded
value." required="yes" type="any" _type="string" />

<cfif Len(Trim(dateAdded)) EQ 0>
<cfset dateAdded = Now()>
</cfif>
<cfset super.SetDateAdded(dateAdded)>
</cffunction>

Is there a better place to do something like this for new records?

Chris Blackwell

unread,
Dec 18, 2009, 6:12:16 AM12/18/09
to reactor-users
to set dateadded whenever a new user record is created you can do that in the custom UserTO.cfc
<cfset this.dateadded = now() />

this will obviously set the value equal to when the object was created, so if theres a delay between the object creation and persisting the record to the database the value will be off.  If you need the precise time the record was persisted to be set when the record is saved you can override the beforeSave() function in your custom record

in /your/path/to/custom/UserRecord.cfc

<cffunction name="beforeSave" access="private">
   <cfif NOT this.getUserID()>  <!--- or however you test for your record being new --->
      <cfset this.setDateAdded(now()) />
   </cfif>
   <cfset super.beforeSave() />
</cffunction>

Cheers, Chris



2009/12/17 Chuck Savage <ch...@searisen.com>

--

You received this message because you are subscribed to the Google Groups "Reactor" group.
To post to this group, send email to reacto...@googlegroups.com.
To unsubscribe from this group, send email to reactor-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/reactor-users?hl=en.



Chuck Savage

unread,
Dec 18, 2009, 11:31:17 AM12/18/09
to reacto...@googlegroups.com
Thanks for the reply Chris.

I've wondered what a TO object was.  So your saying they are initialization values?  IE they have the values before you really get access to a new data record?  Cause you say obviously, it isn't yet to me.

Thanks again,
--
Chuck Savage
http://SeaRisen.com

Chris Blackwell

unread,
Dec 18, 2009, 1:31:16 PM12/18/09
to reactor-users
Hi Chuck,

you're right it probably isn't obvious :)
I believe TO stands for Transfer Object (no connection to transfer orm).  in other patterns they are often refered Value Objects and are simply an object which exposes its properties in the "this" scope.  Reactor uses TO's to pass between Records and DAO when saving/loading.

Any values set in the TO will be the defaults for that field for a new record, so whilst they are not purely for initialization they do have that effect.

HTH, chris

2009/12/18 Chuck Savage <ch...@searisen.com>
Reply all
Reply to author
Forward
0 new messages