How to add an Object to an Array?
Hello, I am new to Coldfusion, so I may be going down a wrong road to solve this problem of mine. The problem is when I invoke a CFC function with a returntype set to Query, the property names in the returned array are all uppercase. But when I invoke a CFC function with a custom datatype, the property name's case are preserved to camelCase. And when I deserialize the object in a Flex app, I want to use the same value object without using a conditional statement to figure out what function the object is coming from in the CFC.
So I decided that I should do a query (step 1), declare an array (step 2), and then populate the new array with the values in from the query (step 3). However I can't find a way to attach properties to an Array. Hopefully the code below will highlight my attempt. The code in red, is giving me an error.
If you understand my goal and know of a more ideal way to accomplish this problem, please post.
Thanks.
<cffunction name="getUsers" returntype="Array" access="remote">
<!--- 1. Do the query --->
<cfquery name="qUsers" datasource="#dsn#">
SELECT *
FROM Users
</cfquery>
<!--- 2. Declare the array --->
<cfset userListArray = ArrayNew(2)>
<!--- 3. Populate the array row by row --->
<cfloop query="qUsers">
<cfset userListArray[CurrentRow]["firstName"] = FIRSTNAME>
<cfset userListArray[CurrentRow]["lastName"] = LASTNAME>
</cfloop>
<cfreturn userListArray />
</cffunction>
