Skip to content

Instantly share code, notes, and snippets.

@atuttle atuttle/deORM.cfm
Created Apr 29, 2016

Embed
What would you like to do?
<cfscript>
function deORM( obj, depth = 1, depthLimit = 10 ){
var deWormed = {};
if (depth >= depthLimit){
return {};
}
if (isSimpleValue( obj )){
deWormed = obj;
}
else if (isObject( obj )){
var md = getMetadata( obj );
do {
if (md.keyExists('properties')){
for (var prop in md.properties){
if (structKeyExists(obj, 'get' & prop.name)){
if ( !prop.keyExists('fieldtype') || prop.fieldtype == "id" ){
deWormed[ prop.name ] = invoke(obj, "get#prop.name#");
}
}
}
}
if (md.keyExists('extends')){
md = md.extends;
}
} while(md.keyExists('extends'));
}
else if (isStruct( obj )){
for (var key in obj){
deWormed[ key ] = deORM( obj[key], depth+1, depthLimit );
}
}
else if (isArray( obj )){
var deWormed = [];
for (var el in obj){
deWormed.append( deORM( el, depth+1, depthLimit ) );
}
}
else{
deWormed = getMetadata( obj );
}
return deWormed;
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.