Created
April 29, 2011 00:36
-
-
Save dustinmartin/947636 to your computer and use it in GitHub Desktop.
Populate Method for CF9 ORM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
public void function populate(required struct memento, | |
boolean trustedSetter=false, | |
string include="", | |
string exclude="", | |
string disallowConversionToNull=""){ | |
var object = this; | |
var key = ""; | |
var populate = true; | |
// Populate Bean | |
for(key in memento){ | |
populate = true; | |
// Include List? | |
if( len(include) AND NOT listFindNoCase(include,key) ){ | |
populate = false; | |
} | |
// Exclude List? | |
if( len(exclude) AND listFindNoCase(exclude,key) ){ | |
populate = false; | |
} | |
// Populate? | |
if( populate ){ | |
// Check if the setter exists or if trusted setting is on | |
if( structKeyExists(object,"set" & key) or trustedSetter ){ | |
// If the value is blank it might be converted to null | |
if( isSimpleValue(memento[key]) && trim(memento[key]) == "" ){ | |
// Check if this value should be kept as a string instead of converted to null | |
if( len(disallowConversionToNull) AND NOT listFindNoCase(disallowConversionToNull,key) ){ | |
evaluate("object.set#key#(memento[key])"); | |
} | |
else { | |
// Set the value to null | |
evaluate('object.set#key#(javacast("null",""))'); | |
} | |
} | |
else { | |
evaluate("object.set#key#(memento[key])"); | |
} | |
} | |
} | |
} | |
} | |
</cfscript> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
if(form.value== ""){ | |
object.setValue1( javacast("null","") ); | |
} | |
else { | |
object.setValue1(form.value); | |
} | |
</cfscript> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
object.populate(form); | |
</cfscript> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
object.populate( | |
memento = form, | |
disallowConversionToNull = "someProperty,anotherProperty" | |
); | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment