I am creating a blog API and I am having some very strange problems trying to create an array of structures in coldfusion. The top-level array will contain a post as a structure, with .comments, which is an array of all the comments in this post, as well as structures.
Each of the parts in the following code works individually. But somehow, when I add them, I end up with an infinitely nested array of structures containing an array of structures, etc ... just the very last element in the top-level message array.
<cfset posts = VARIABLES.postDao.getBlogPosts(argumentCollection=arguments) /> <cfset result = arraynew(1) /> <cfloop index="i" from="1" to="#arrayLen(posts)#"> <cfset post = posts[i].getInstance()> <cfset StructInsert(post, 'comments', getComments(post.postId))> <cfset ArrayAppend(result, post)> </cfloop>
getBlogPosts returns an array of beans messages.
bean.getInstance () returns a structure with all the data in the bean.
getComments (id) returns an array of all comments (structs) for post [id].
Each of them works as intended and is used in other places without problems.
The structure of an infinitely nested array is as follows:
Array containing Post . Post.comments containing array of comments + Post on end . . Post.comments containing array of comments + Post on end . . . etc...
source share