A quickie tip that is (for me) easy to forget some days: I have a table with a foreign key. For certain reasons, I’m not creating a Transfer relationship with this foreign key and I want it to default to NULL. The object is defined like so in transfer.xml:
<object name="club" table="tblclub" decorator="model.club.club">
<id name="ClubID" type="UUID" generate="true" />
<property name="ParentID" type="UUID" nullable="true" /> [my foreign key]
<property name="Name" type="string" />
</object>
For <id>, Transfer gives you back a “NULL” UUID of all zeros. If you have a <property> however, it gives you back the defaults as listed here. In case of a UUID, such as ParentID, it’s just a random UUID. To set your own defaults that override these values on a per-object basis, simply add a “configure” method to your decorator:
<cffunction name="configure" access="public" returntype="void" output="false">
<cfset setParentIDNull() />
</cffunction>
The configure() method is run automatically after init() by Transfer. Now when I execute transfer.new(“club”), the value returned from getParentID() is a UUID of all zeroes (the equivalent of NULL).
Comments are closed.