Recently, I’ve been messing around quite a bit with ORM in ColdFusion. I really like the benefits that it brings to developing applications. However, I noticed a very big bug yesterday while attempting to user serializeJSON() on a an entity using a one-to-many relationship.

Some Context

Let’s say that you have two entities that are related via a one-to-many relationship (Artists and Art, for example). You can easily create this relationship in your model by doing something like the following:

property name="art" fieldtype="one-to-many" fkcolumn="artistid" cfc="Art" remotingfetch="true";

If we were to dump the result of an EntityLoad() of “Artists”, we’d see a nice structured relationship: First, an array of all Artist entities, and then an array of all Art entities related to the particular ArtistID. Additionally, I’ve specified remotingfetch=true, which will force CF to load the Art entities for each Artist.

The Bug

The bug, however, comes into play when you try to serialize the result of EntityLoad(). While it properly composes the relationships, it represents the first two entities in the “art” array; any subsequent entities in the given array are returned simply as “{}”.  Whether you have 3 “Art” entities for an artists, or 20, only the first 2 will ever be serialized properly.

See More >