I like the new Grails 2.0 “where” queries but need to do a projection. Anyone know how? Right now I have code that instantiates all the domain instances and extracts the field I need:
List<Double> eloRatings = User.where { !deleted }.list()*.eloRating
This isn’t very efficient.
From this blog post, you can’t use projections directly with
wherequeries. However, since the returned object from awherequery is aDetachedCriteria, you can append a traditional criteria to it, like so:This should work, I tested it under Grails 2.0.