I am converting an old site into CF 10 and would like to transfer some of my helper code.
The code scans the request, finds the things that are in our instance, and fills them:
<cffunction name="populateSelf"> <cfargument name="source" type="query" required="yes" /> <cfif arguments.source.recordcount EQ 1> <cfloop list="#arguments.source.columnlist#" index="local.col"> <cfif structKeyExists(variables.instance, local.col)> <cfset variables.instance[local.col] = arguments.source[local.col]) /> </cfif> </cfloop> </cfif> </cffunction>
I replaced structKeyExists(variables.instance, local.col) convenient evaluation of our current properties using 'getMetaData ()', but I am having problems with the following line: <cfset variables.instance[local.col] = arguments.source[local.col]) />
If I change it to <cfset this[local.col] =arguments.source[local.col] /> , it ignores the implicit setters and simply puts the results in this area ...
To try calling our setters, I tried this bit of code:
<cfset setValue =arguments.source[local.col] /> <cfset evaluate("set#local.col#('#setValue#')" />
but this seems complicated and error prone (you should also avoid any "" in lines).
What is the best way to use a query to load some or all of the properties of CFCs without explicitly calling this.setPROPERTYNAME(query.COLUMN) , perhaps several dozen times?
source share