Posted By

daspoda on 08/22/12


Tagged

ColdFusion cfwheels compositekes


Versions (?)

renameForCompositeKey


 / Published in: ColdFusion
 

RenameForCompositeKey

Helps with creating new composite key objects by renaming the keys to include a blank id

@structure, structure to rename keys on @keyPosition, position of the provided key

  1. <cffunction name="renameForCompositeKey" returntype="struct">
  2. <cfargument name="structure" required="yes">
  3. <cfargument name="keyPosition" required="yes" type="numeric">
  4. <cfset LOCAL = StructNew()>
  5.  
  6. <!--- create temporary structure copy --->
  7. <cfset LOCAL.temp = structure>
  8.  
  9. <!--- clear structure --->
  10. <cfset structure = StructNew()>
  11.  
  12. <!--- loop through keys, and repopulate struct --->
  13. <cfloop collection="#LOCAL.temp#" item="key">
  14. <cfif keyPosition EQ 1>
  15. <cfset structure["#key#,"] = LOCAL.temp[key]>
  16. <cfelse>
  17. <cfset structure[",#key#"] = LOCAL.temp[key]>
  18. </cfif>
  19. </cfloop>
  20. <cfreturn structure>
  21. </cffunction>

Report this snippet  

You need to login to post a comment.