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!
Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.
Comments
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)
}
Maybe you will like nike shox shoes,welcome to http://www.buddshox.com
nike shox shoes
We are the best Timberland shoes online,and we can offer all of the Timberland serious products,Timberland men shoes,Timberland women shoes Timberland boat shoes,Timberland UK with the top quality,the Timberlasnd shoes are hot sale for these days,for the Christmas you can purchase cheap timberland shoes,may be you will recieve the timberland boot as a gift.
Tom Penny and Antwian Dixon. Apart from a large fan base compromising skateboarders, supra vaider high tophas also caught
the attention of the music industries big names such as Jay-Z, Justin Timberlake and Lil Wayne.supra vaider black high
boots, it is the main supra vaider teal we push in our online shop these days.
If you are looking for abercrombie and fitch clothing,our nike shop store online is your best choice. You can save 40% each pair now and also you find your favorite abercrombie & fitch clothes with high quality and dizzing array of colors and patterns. Strong grips,durable ankle support,and relative comfort attract skateboarders to abercrombie clothes. abercrombie and fitch clothes are considered as the most desirable skateboard shoes.Like everything with skateboarding,you should do what you want. our professional crew is available for you at any time, Enjoy happy Shopping.

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!