Transfer: First Impressions

Last night I downloaded and looked at Transfer, a ColdFusion based ORM, for the first time. To be clear, it’s the first time I’ve looked at any ORM. I’m more than a little unhappy. What the hell is wrong with me that I’ve never made an effort to use Transfer before? (that’s a rhetorical question. there’s not enough gigs of storage space on the Internet to answer. k thx).

How did this all finally come about? I’m working on a project that’s my first Model-Glue app that actually makes use of objects. I was told to use Transfer by more than a few people, but I didn’t want to add any more to the learning curve. It seemed to me that learning Model-Glue, ColdSpring, and OO was quite enough for my little brain.

I got to a point the other day where I had a particular object. This object had a property that was essentially another object. That particular object was an array of different objects. Trying to create this composite object was more than a little daunting. I was actually ready to just pull the OO stuff out and go back to a procedural model. Jon Messer, a co-worker of mine and all around super-intelligent guy, told me to at least take a look at Transfer before i considered such a drastic step. When Jon talks, I listen (hey he’s not only super-intelligent, but he’s also a big guy that could beat me into an unrecognizable jelly).

I got home yesterday around 7:30pm, and I was exhausted. I had little enthusiasm or motivation for taking on yet another new thing right then and there. But I went ahead and started the download and made the necessary configuration changes in my ColdSpring.xml.

Issue #1 hit me pretty quick. Model-Glue didn’t recognize that I was using an ORM. Scott Stroz hopped on a Connect session with me, looked over the code, and it all looked right. With few other alternatives to consider, he suggested I update ColdSpring to the latest nightly build. Normally, i don’t like BERs and nightly builds. I generally opt for stability over new features that could potentially break my apps. But I went ahead and grabbed the nightly build, and voila. Model-Glue was happy. Lesson learned… even if you think you’ve got a pretty recent version of ColdSpring, the nightly build (in my opinion) actually fixes a number of issues (or perhaps more accurately adds a bit of functionality). Go for it.

After that, it was pretty much smooth sailing. As tired as I originally was, I was up until 2:30am messing around with the Transfer.xml file, defining the objects from my database tables. It was amazing (in a very, very, very geeky kind of way). Using relatively straightforward XML, not only could I create an object, but an object that has a property that’s an array of other objects in under 10 lines of XML.

How’s it done? Let’s say you have a user object. The user has a property called ‘territories’. A given user can have more than one territory. So if “User” is an object, and “Territory” is an object, and the user has a property that’s an array of territory objects… difficult for a novice to create that object from scratch. How easy does Transfer make it?

<object name="User" table="tbl_User">
	<id="userID" type="UUID" />
	<oneToMany name="Territory">
		<link to="Territory" column="userID" />
		<collection type="array" />

<object name="Territory" table="tbl_Territory">
	<id="territoryID" type="UUID" />
	<property name="territoryName" column="territoryName" type="string" />

So that’s actually 11 lines of code. Sorry for misleading. But that’s literally all that’s required. My application will now have the concept of a Territory object (no need for a Territory.cfc!), as well as the concept of a User object (no need for a User.cfc!). The User object will have a property called getTerritory() that will be an array of all of the territories that belong to the user (all territory records in the territory table that have the corresponding foreign key UserID).

And this is all just the tip of the iceberg. I have yet to get into composite keys and decorators, but plan on doing that tonite. Yeah, I’m exhausted but this is just way too wicked cool :)

Huge thanks to Mark Mandel and everyone who’s contributed to Transfer in one way or another. You’ve got some drinks coming your way at cf.Objective().