ColdFusion 9 ORM, findBy, searchBy, countBy and more…

When ColdFusion 9 was in its very early stages I raised an Enhancment Request where we could use these as part of the persistent Entity or as it should be know Domain Class.

Adobe in their wisdom chose to ignore this E/R, because they thought the users would not be up to understanding it.

In the last few days there has been a few blogs by Dan Vega on his interpretation of how it needs to be implemented. And Dan nothing against your attempt, you should be doing it at the persistent / domain class layer and not the service layer.

I have been working on this for the last few months, and like Dan I am a bit further into it that he is. Unlike Dan I have not only got FindBy, SearchBy, but I also have implemented groupBy, FindAllBy, searchAllBy. And also unlike Dan, I am in the process of finalising the last stages of it where I can do something like this.

myDomainClass.FindbyFieldNameandFieldName2Like(arg1,arg2);

I also have the following implemented.

myDomainClass.FindbyDateBetween(arg1,arg2);

This is just some of the things I am able to do, other things I am in the process of finalising is notequals, equals, like, ILike to name a few.

It would have been good if Adobe saw the need for this and implemented it under the hood on the persistent component where it belongs, until then I will be releasing my version that has been in development for the last few months.

So imagine doing this.

myDomainClass.countByFirstnameOrLastname('scott');

I have a few things to sort out first but it is almost there, and it is far superior to What Dan has done over at http://www.danvega.org/blog/index.cfm/2009/12/21/Abstract-Service-Level-Demo because I do it the way it should be done, and as Grails has done it.

Sometime in the new year I will release this, and I hope you all can get behind me and get Adobe to introduce it the way it should be done. under the hood, and on the persistent component.



  • Dan Vega's Gravatar It is funny you mention Grails and the domain level. This morning as I was coming into work I was just thinking how I started creating very Grials like code and that maybe it does belong at the domain level. You planning on sharing your code?
    # Posted By Dan Vega | 12/22/09 6:06 AM
  • Dan Vega's Gravatar The only difference though is that Grails is a framework and makes these domain classes available to the controller so there is no need for another layer. With no framework in place the easiest way to make these methods available to my template is by using the service. I expect this to evolve as I come across issues.
    # Posted By Dan Vega | 12/22/09 6:18 AM
  • David Buhler's Gravatar Are you going to be posting it to RiaForge?
    # Posted By David Buhler | 12/22/09 7:14 AM
  • Tony Nelson's Gravatar Can you provide an example of how you would use this in ColdFusion, rather than saying "myDomainClass.findByWhatever()"? Would you need to first create a new instance of the domain class, something like:

    art = new Art();

    items = art.findByPrice('100.00');

    If so, I don't know if I totally agree with that approach, since you're creating a new instance of a class that returns instances of itself. To me it makes more sense to put that logic inside of a service.
    # Posted By Tony Nelson | 12/22/09 9:16 AM
  • Matt Woodward's Gravatar It really is too bad this (and a lot of other stuff) didn't make it into the CF 9 ORM.

    @Dan--after working with Grails quite a bit I'm starting to think that CF would be better off if it embraced the fact that it's much more a framework than people think it is.
    # Posted By Matt Woodward | 12/22/09 2:00 PM
  • Andrew Scott's Gravatar @David - Yes I will be releasing it sometime just into the new year, there are a few issues at the moment that I need to address. But to give an idea I am modelling this off GORM Dynamic Finders">Dynamic Finders

    @Tony - I disagree with you about having it at the service layer, this is an always will be manipulation of sql queries that should be done at the Domain Class level. There are plenty of examples on how to use this over at grails websites.

    @Matt - I agree, however Adobe's attitude was clear cut. Nobody in their market would actually use it and it would be to confusing for the average user. And when I was on the pre-release that is what I was told by Adobe and other so called community experts. So the raised E/R was SP5'ed by Adobe.
    # Posted By Andrew Scott | 12/22/09 2:49 PM
  • Tony Nelson's Gravatar I'm familiar with how Grails does it. I'm more curious as to how you would do it in ColdFusion.
    # Posted By Tony Nelson | 12/23/09 8:35 AM