Let\'s say I have definied a User object using GORM. Each user can have zero or more Login:s. Each Login has a timestamp. When retrieving user.logins I want the logins to be sor
Just make the Login Class implement the Comparable interface:
class Login implements Comparable {
// ...
Date date
public int compareTo(def other) {
return date <=> other?.date // <=> is the compareTo operator in groovy
}
}
and declare the relation to be a SortedSet:
class User {
...
def hasMany = [logins: Login]
SortedSet logins
static fetchMode = [logins: "eager"]
}