Viewing By Entry / Main
Dec 14, 2007
ActiveRecord with Transfer ORM
Sean Corfield's recent comment on a post by Peter Bell turned on a light bulb in my head this morning. Basically, his comment was that a decorated bean in Transfer ORM already has access to the Transfer framework. What this means is you can easily access any of the functionality of Transfer from within the decorator.
Let's look at an example of what this allows you to do. Now, I will preface this by saying that I am not a big fan overall of the ActiveRecord pattern, but let's say you wanted your bean to know how to persist itself... Well, you can implement that in exactly three lines of code within your decorator.
<cffunction name="save" access="public" returntype="void" output="false">
<cfset getTransfer().save(this) />
</cffunction>
Now all you need to do is something like bean.save() and your object, along with all its relevant relationships (i.e. hasMany, hasOne, etc.) will be persisted.
Thanks for the tip Sean!
Comments
And thereby bring the ActiveRecord/DAO bastardization from reactor to Transfer. You are gonna give Transfer an identity crisis. :)
Sweet! Easy and effective for getting Active Record in Transfer! I've been studying your CFC Composition posts over the last couple days, and watched a Transfer preso by Mark, trying to grok it all. I always preferred Reactor and Active Record pattern at a theoretical level (without ever using either Reactor or Transfer... I just mean that's the slant I got when reading everything), but now as I get ready to actually start coding some stuff, I see the down side to implementing an Active Record pattern, even in a Transfer decorator. It ties your bean to the ORM by overstepping the service.
Interesting, nonetheless!!
Interesting, nonetheless!!
