I have a frustrating problem with the criteria builder. I have an application in which one user has one calendar, and a calendar has many entries. Seems straightforward enough, but when I try to get the calendar entries for a given user, I can't access the user property (MissingMethodException). Here's the code:
def getEntries(User user) {
def entries = [ClassName].createCriteria().list() {
calendar {
user {
eq("id", user.id)
}
}
}
}
I have even tried the following variation:
def getEntries(User user) {
def entries = [ClassName].createCriteria().list() {
calendar {
eq("user", user)
}
}
}
That did not raise an exception, but didn't work either.
Here's the relevant parts of the domain classes:
class Calendar {
static belongsTo = [user: User]
static hasMany = [entries: Entries]
...
}
class User {
Calendar calendar
...
}
class Entry {
static belongsTo = [calendar: Calendar]
...
}
When Googling I came across a similar problem noted in early 2008: http://jira.codehaus.org/browse/GRAILS-1412
But according to that link this issue should have been solved long ago.
What am I doing wrong?