No patience for Grails

Yet another case of not enough damn useful documentation. I really wanted to give Grails a shot and started to build a simple 2 domain object app. On the User list view I wanted, what seemed like, a simple requirement, to show the latest Report object available for each user.

So, I started looking through the docs and found all the nifty dynamic query methods, but nothing that allowed me to query through the object model. Ok, so I tried (in the User class):

def lastReport = Report.findByUserId(id)
Didn’t work. Ok, how about:
def lastReport = Report.findByUser(id)
Nope. Ah, then I found a reference that lead to me try:
def lastReport = Report.findByUser( User.get(id) )

Nada. Now I’m frustrated. Several Google searches later and nothing. All kinds of worthless examples that show querying single objects and a few criteria builders, but all relating to a single class, nothing parent-child.

As my previous post mentioned, I’m exploring Ruby on Rails as well for another simple project. After thinking about it, one thing came to mind. Ruby starts with the data model and goes up. Grails seems to go the other way around. The docs weren’t even clear as to if I need to specify an ID field or not(?). I know you can hand map Grails however.

I’m sure the solution to this particular problem is pretty easy, but the docs should definitely cover things a tad more difficult than querying a single object. Seriously, anybody who is building that simple of an app doesn’t need Grails or RoR or whatever.

In the time I spent looking for how to accomplish this I could have hand built the whole thing, and I’m not exaggerating. If you are going to force me to work through an object model at least make it easy to do so, and so far it isn’t easy. I don’t want to give up on Grails just yet (or Ruby on Rails for that matter), but if I can’t figure out how to do a simple query that would take all of 20 seconds to write in SQL it makes a bit hard to call these frameworks ‘productive’.



Don't miss anything, subscribe!

7 Responses to “No patience for Grails”


  1. 1 Graeme Rocher

    Should have asked on the list, we’re pretty helpful ;-)

    Your third example should work. You can always enable SQL logging to see what Grails is doing in the background (or hibernate for that matter). Just do

    def logSql = true

    On the *DataSource.groovy file in grails-app/conf

    There is actually an example of querying relationships on http://grails.org/GORM+-+Querying

    Also you should checkout Jason’s free book which has a lot of info http://infoq.com/grails

    There is mine too, but that one costs money so to speak :-)

    Anyway, hope you don’t give up. Enjoy Grails!

  2. 2 The Bull

    Thanks for the pointers Graeme. I’m not giving up yet that is for sure. I’m hoping that we can use Grails more and more for some of the work we have to do.

    And yes, I should have gotten on this list :-)

    Thanks again!

  3. 3 Przemyslaw Dul

    I have same Problem…
    Grails seems not to be able to resolve such findby yet.
    It would work, if your report has only one user (like a book has one author on http://grails.org/GORM - Querying ), but not if your report hasMany users.
    Instead use
    Report.withCriteria{
    user {
    eq(’id’,user.id)
    }
    maxResults(10)
    }

  1. 1 Thinking Outloud » Blog Archive » A pretty darn good Grails example
  2. 2 Mutual Funds and Market Research
  3. 3 Business Ideas Forum
  4. 4 New and Used Book Reviews

Leave a Reply