ColdFusion’s serializeJSON(): Query of Query vs Database Query

So I was working on an ajax request that reloads a select based on it's dependency to the selection made in an adjacent select, and noticed that all of a sudden, the javascript helper I was using was no longer working.  This came as a surprise as this had been stable for quite some time and the scenario I was using it for seemed identical to those I have used it for in the past.  After spending some time looking into it, I realized the problem.  My function that returned the results to reload the select in this scenario was using a Query of Query, where in the past I had always been returning a Query result straight from the database.  Upon taking a peak at the actual JSON object returned from serializeJSON() and realized that the keys for the data object returned from a normal Query would always return in all caps, and the JavaScript followed this assumption.  The Query of Query actually returned the keys in the exact case used for the select in the query itself.  Look at this example to see what I mean:

ColdFusion:
  1. <!--- ColdFusion query against the database with it's json string ---> 
  2. <cfquery name="getResources" datasource="#helpers.config.getDatasource()#">
  3.     select id, name
  4.     from sport
  5.     group by id, name
  6.     order by name
  7. </cfquery>
  8.  
  9. {
  10.     "ROWCOUNT":2,
  11.     "COLUMNS":["ID","NAME"],
  12.     "DATA": {
  13.         "ID":["1","2","3"],
  14.         "NAME":["Football","Baseball","Soccer"]
  15.     }
  16. }
  17.  
  18.  
  19.  
  20.  
  21.  
  22. <!--- ColdFusion query of query with it's json string ---> 
  23. <cfquery name="getResources" dbtype="query">
  24.     select id, name
  25.     from [local].getSports
  26.     group by id, name
  27.     order by name
  28. </cfquery>
  29.  
  30. {
  31.     "ROWCOUNT":2,
  32.     "COLUMNS":["ID","NAME"],
  33.     "DATA": {
  34.         "id":["1","2","3"],
  35.         "name":["Football","Baseball","Soccer"]
  36.     }
  37. }

One Comment

  1. jbanken@gmail.com Says:

    Interesting find. I would imagine that query of query object would be treated the same as a query object. I wonder why it changes?

Leave a Reply

You must be logged in to post a comment.