Grails

Querying Domain class with hasMany String Type

In my recent project there was a use case where I had to query domain's hasMany but relationship was not with any domain class but rather String type. Consider example [java] class Blog { static hasMany = [tags: String] } [/java] Now to find all the blogs with tag "grails" , our normal way of querying hasMany relationships...

by Puneet Behl
Tag: createCriteria
25-Sep-2012

Grails

Using aliases in aggregate functions of criteria queries

When using criteria queries, many times we encounter a use case where we need to order our result not on any field of domain class but on our result set, in these cases aliases can be used. In my project, use case was to find most liked products from the domain: [java] ProductStat{ Date dateCreated Product product } [/java] ...

by Puneet Behl
Tag: createCriteria
13-Feb-2012

Grails

Criteria Query and pagination params

I have been using the following code to get paginated result and the total number of results returned irrespective of the pagination params. def result=SampleDomain.createCriteria().list(){ // multiple restrictions maxResults(params.max) firstResult(params.offset) } // Return type is ArrayList Integer ...

by Bhagwat Kumar
Tag: createCriteria
14-Jul-2010

Grails

Grails criteria query example for unidirectional one-to-many relationships

Following is an example of unidirectional one-to-many relationship: class Employee { String name static hasMany = [roles: Role] } class Role { String name } How can we find all the employees with a particular role - "Grails Developer"? Role role = Role.findByName("Grails Developer") One way of doing...

by Aman Aggarwal
Tag: createCriteria
14-Jun-2010