the singularity of being and nothingness
ColdFusion

ContentBox: Editable Content Regions in CKEditor
Jan 2nd
I recently created a module for ContentBox that allows you to embed “fiddles” from the excellent http://jsfiddle.net. If you’ve not used this site before, you really should 🙂
In developing this module, I had very specific goals, particularly for the user interface in the rich HTML content editor, namely CKEditor. My goals were simple:
- Have toolbar icon for easy insert
- Allow easy insert from context menu (right-click) within the content editor area
- After content/config/whatever is inserted into content editor area, show something meaningful (other than ugly red iFrame box)
- Allow user to act on inserted content–particularly, be able to edit all the properties of the content that were configured pre-insert
The first two are really easy. If you look at the source of the PasteBin module, you’ll see really quickly how to do those, so I’m not going to dwell on that. In this post, however, I do want to show how simple it is to make inserted content regions richly editable, treating them like complex data, rather than just simply strings.
Insert Content RegionNOTE: In the following, I include code-snippets, but often omit unimportant or redundant bits. Be sure to grab the entire source to see everything in its full context 🙂
Before we look at creating the editable More >

ColdFusion ORM – Collection…was not processed by flush()
Nov 14th
This is more for my own memory, but perhaps it will be useful to others 🙂
Let’s say I have the following entities:
User.cfc
component persistent="true" entityname="User" table="User" { property name="UserID" fieldtype="id"; property name="Name"; property name="Age"; property name="Group" fieldtype="many-to-one" cfc="Group" fkcolumn="GroupID"; }
 Group.cfc
component persistent="true" entityname="Group" table="Group" { property name="GroupID" fieldtype="id"; property name="Name"; property name="Activities" fieldtype="one-to-many" fkcolumn="GroupID" linktable="Activity" inversejoincolumn="ActivityID"; }
Ok, so let’s also imagine that I’m trying to leverage the postDelete() event to make an audit record of any User deletions that I make:
// function postDelete( entity ) { // get properties from entity that I want to log ... ... }
When I try to do this, I get something like:
collection >> [Group.Activities] was not processed by flush()
I banged my head on this wall for a while, until I finally figured out the issue.
The issue is the “laziness” of the “Group” property on the User entity. Since I have no value specified, it is equivalent to having specified “lazy=true”. Since (I assume) the Group property is not being fully “loaded” during the delete operation, there’s no chance that it’s own “Activities” property is loaded either…hence the error.
Anyway, to fix this, I merely added “lazy=false” to my “Group” property. Once in place, I was able to More >

Custom SQL Projections…Part Second
Sep 5th
Previously, I outlined a way in which you can pretty easily extend ColdBox’s excellent CriteriaBuilder to support Hibernate Criteria SQL projections. While this certainly worked, you may remember I complained–whined, really–about how hard-codey the solution was. That is, in order to really use the SQL projections, you more or less have to build out SQL strings manually each and every time you use it. String concatenation, ugh!
Not content to leave it alone, I continued to explore ways to make this a bit better; I think I’ve struck on a significantly better way.
On the Road to a SolutionWhat I’ve created is what I call a “Detached SQL Projection”. In essence, it leverages the DetachedCriteria which I wrote about previously. Once the DetachedCriteria is sufficiently built up, the “projection” more or less grabs the SQL that *would be* generated for the DetachedCriteria. However, instead of adding it as a subquery to the main criteria object, this faux-projection uses the pre-generated SQL and creates a real SQL projection.
Here’s some code (from my extension of the withProjections() method):
// detachedSQLProjection if( structKeyExists( arguments, "detachedSQLProjection" ) ) { var propertyTypes = [];   var sqlargs = arguments.detachedSQLProjection;   var metaData = orm.getSessionFactory(orm.getEntityDatasource(this.getentityName())).getClassMetaData(this.getentityName());   // get session   var More >

Custom SQL Projections in CriteriaBuilder
Aug 25th
In my last post, I showed how you can pretty easily integrate ColdBox’s awesome CriteriaBuilder with subqueries. As I was using this approach, I came across another (unrelated) challenge that I wanted a solution for.
Simple Grouping/SummingIn one of my queries, I wanted to do some simple grouping/summing. With CriteriaBuilder, you can do this very easily by adding a projection or two.
For example, let’s imagine that we have the same entities as before:
- Car
- Driver
- Insurance
This time, we want to get a sum of the total number of cars, grouped by “make”. Easy:
public struct function getCarsByMake() { var c = newCriteria(); c.withProjections( count="CarID", groupProperty="Make" ); var results = { data = c.list() }; results.count = arrayLen( results.data ); return results; }
And the SQL:
select this_.Make as y0_, count(this_.CarID) as y1_ from Car this_ group by this_.Make
Pretty simple. By the application of the “count” and “groupProperty” projections, we get back a nice array of the grouped data. Note, of course, that because of the application of projections, our result set is no longer in the domain of discreet entities. Rather, since we asked for aggregate data, that’s what we get! Of course, this means that results.count has to be calculated differently. Instead of running CriteriaBuilder’s count() method More >

Subqueries with ColdBox CriteriaBuilder
Aug 20th
Here is the code on GitHub, if you want it.
Over the last several months, I’ve been working heavily in a brand-new environment (to me): one that is built upon ColdBox and leverages all of the awesome goodies that ColdBox provides in the way of rapidly and easily developing ORM-driven applications. If you spend more than 3 minutes in a ColdBox ORM app, you’ll quickly come to rely upon–and LOVE–ColdBox’s CriteriaBuilder, which lets you easily build intensely complicated HIbernate criteria queries…without the nonsense of string concatenation.
The other day, however, I ran into a bit of a wall. Before I explain the issue, let me give a quick summary of the context.
In my app, I have a good number of concrete services that extend the uber-handy Virtual Entity Services. Since my app is driven largely by an AJAX frontend, there are lots of cases in which I not only want to return a JSON-representation of a result set, but also important meta-data about the result set (e.g., total record count for paging, etc.). Obviously, since I want that bundled into one single response, I have lots of methods that do something like so in one of my concrete services:
function getResults( event, rc, prc More >

Gloss Updated with ColdFusion 10 Documentation
May 16th
On the heels of yesterdays’s official release of ColdFusion 10, I’ve updated Gloss with support for both ColdFusion 10 AND ColdFusion 9 reference guides.
Enjoy!
Share this:
ColdFusion Bug? EntityToQuery() and Unknown Data Type
May 2nd
I ran into an interesting issue today. To make a long story a little less uninteresting, I was basically trying to go from an array of ORM entities to an Excel dump of the data in those entities. Obviously, the easiest way to accomplish this is to first convert the array of entities to a query, and then pass the query result set off to the built-in CF Excel manipulation functions.
Easy enough. With one little line of code, you can very simply convert ORM entities to a ColdFusion query…just like so:
// get the orm entities ormstuff = EntityLoad( "Art" ); // convert the orm goodness to a CF query anicequery = EntityToQuery( ormstuff );
Cake, right? If I were to hand this query off to CF’s spreadsheet functions, I could easily prepare and export a nice Excel file full of the data I just converted. But of course, nothing is that simple…and that’s where the potential bug announced itself.
A Dark ForebodingYou see, instead of simply dumping all the data for all the columns of the query-which-was-once-an-entity, I wanted to pare down the list of columns that would be output in the Excel export. Since I already had a query handy, More >

ColdFusion Bug: SerializeJSON() and ORM Entities
Apr 26th
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 ContextLet’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 BugThe 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 >

ColdFusion 10 Beta Examples are Live
Feb 25th
I recently created a free ColdFusion 10 Beta hosting account with Hostek.com. It’s pretty awesome, so you should create one too!
Anyway, with that in place, I’ve uploaded my examples of ArrayEach(), StructEach(), and ArrayFilter(). I’ve also put them out on GitHub, so feel free to take a look if it suits you.
Enjoy!
Share this: