Peter Boughton
Peter Boughton

Reputation: 112150

Is there a way to globally apply top attribute to cfdump/writeDump when dealing with ORM objects?

When dealing with nested ORM relations, using cfdump or writeDump can rapidly result in java.lang.OutOfMemoryError errors because CF attempts to resolve relations in nested objects and dump too many objects.

This can be avoided with the top attribute, for example: <cfdump var=#SomeObject# top=3 />

It's a pain to remember to write this all the time - is there any way to configure CF to not go down too many levels when dealing with ORM objects?

Upvotes: 4

Views: 204

Answers (1)

Peter Boughton
Peter Boughton

Reputation: 112150

There doesn't appear to be any administrator settings for this. (issue raised)

An imperfect solution is to create a wrapper for the cfdump tag by renaming {cfusion}/wwwroot/WEB-INF/cftags/dump.cfm to (for example) origdump.cfm then creating a new dump.cfm file containing:

<cfif isObject(attributes.var) AND NOT StructKeyExists(attributes,'top')>
    <cfset attributes.top = 3 />
</cfif>

<cforigdump attributecollection=#attributes# />

<cfexit method="exitTag" />

Fortunately, the writeDump function will call this wrapper (so it works for both tag and function).

Unfortunately the wrapper is not called recursively - if the ORM object is in a struct or array then the original problem still manifests itself - it may be possible to pre-scan complex variables to determine if there are relationships inside and set an appropriate top value, but only a limited solution could be achieved with this (i.e. it would affect neighbouring structs/arrays).

Upvotes: 5

Related Questions