CF9 ORM blog sample application

July 31, 2009

Way back in 2005 Mark Mandel wrote an simple blog application to demonstrate how to use Transfer ORM. I thought it would be an interesting exercise to update it to run using the in-built ORM capabilities on ColdFusion 9. While I was at it, I also refactored some of the code to take advantage of some of the new language enhancements as well.

I've set the application app to drop and re-create the database each time the application is run, so you'll want to comment out that line in the onApplicationStart method of Application.cfc if you want to keep the data.

I'm not going to go through each file and explain what is happening as there is too much to show in a blog post, but I've tried to comment the code to help explain what is happening. Feel free to post any questions you have.

This is an extract from the readme file included in the zip, which I'm posting here so that you do read it!


What is it?
----------------------------------------------------
A simple example application demonstrating ColdFusion 9's in-built ORM features.
The original tBlog application was created by Mark Mandel to demonstrate Transfer ORM
which has been converted by me (John Whish) to work using ColdFusion 9 ORM.

Installation:
----------------------------------------------------

* Create a database called 'ormBlog' in either mySQL, MSSQL.
* Create a datasource called 'ormBlog' pointing the database you created above
* Extract the files into your webroot as /ormBlog/
* Run the application (it will build your database)
* You will need to create a user and a category before you can add a post

This is a very lightweight application, with very little in the way of error handling.
It is meant to simply be an example of some of the things that ColdFusion 9 ORM is
capable of.

You can download the zip file here.

Thanks to Mark for letting me hack his code!


8 comments

  1. Awesome!! Downloading right now.

    Comment by Ben Nadel – July 31, 2009
  2. Hi Ben, did I forget to mention that it doesn't actually work...? :D

    Let me know it runs OK for you. I only ran a quick test against MSSQL and MySQL.

    Comment by John Whish – July 31, 2009
  3. No worries. I was gonna try to run it on Derby and NOT in the web root... so, I'm sure I have my work cut out for making it work. More than anything, I just wanted to look under the hood.

    Comment by Ben Nadel – July 31, 2009
  4. I used tBlog as my "learn orm" code base.

    Downloading and going to fire this guy up at lunch.

    Thanks.

    Also your post titled "Getting Meta Data from CF9 ORM" was just waayyyyy to helpful. All that code will permanently be in my base.cfc THANKS for that.

    Comment by John Allen – July 31, 2009
  5. @Ben, should work against Derby, I use a application mapping for the model path so that should work as well. Famous last words? :)

    @John, yeah - I think tBlog caused a 1000 eureka moments. Glad the other post proved useful, it is the core of my ORM applications so I hope it's OK!

    Comment by John Whish – July 31, 2009
  6. Just letting you know my last name doesn't have a 'll' at the end, it's just 'l' ;o)

    Comment by Mark Mandel – August 01, 2009
  7. Mark - sorry! I knew how to spell your name and still got it wrong. Post updated and grovelling apologies offered.

    Comment by John Whish – August 02, 2009
  8. FYI - in your ormBlog code in model Post.cfc you have typo in removeAllCategories()
    var catgeories = this.getCategories();

    Comment by johans – November 23, 2009

Leave a comment

If you found this post useful, interesting or just plain wrong, let me know - I like feedback :)

Please note: If you haven't commented before, then your comments will be moderated before they are displayed.