GORM Recipes

As I’ve been diving into Grails, one of the most frustrating parts I’ve had to deal with has been GORM. It is deceptively easy to do the simple stuff with GORM. But as soon as I got to the point of wanting to do aggregate functions, grouping, or other more sophisticated queries, I ran in to wall.

Rather than diving in to SQL, I opted work through the documentation and various blog posts to find the “GORM Way” of doing things. I also documented what I found. The result is this rather extensive article on GitHub called GORM Recipes.

The text was way too large for this blog, so I opted to put it on GitHub. This thread is for feedback and questions about the GitHub article.

3 thoughts on “GORM Recipes”

  1. Just a simple note about mapping where queries with regular expressions… The blog post covers this fine, but when the regex operator is being used, it does not require the wildcard operator; this will get automatically translated at the GORM layer. That part was just semi-unclear because the preceding example _does_ need the wildcard operator, and the regex example reuses the titleCriteria variable.

  2. Clarifying my comment — so long as the assignment is evaluated to a Pattern object. But, I didn’t mean to imply that your example does not work; including the wildcard operator is fine, but a “Groovier” (at least looking) way to do it might be to have the right-hand side of the expression be a pattern object:

    def list = DomainClass.where { name ==~ ~/Dan.+s$/ }.list()

  3. Cool, thanks Dan. I’ll have to add a recipe using regular expressions to more clearly delineate between the different LIKE queries.

    -Tim

Leave a Reply

Your email address will not be published. Required fields are marked *


*