I have a simple one-to-many association:
class Foo {
int id
Date someDate
static hasMany = [
bars: Bar
]
}
class Bar {
Foo foo
Date someDate
static mapping = {
.....
columns {
foo([:]) {
column name: "id"
}
}
}
}
Under normal circumstances, calling foo.bars will return all Bars, which is fine. But in this case I need to query using the someDate
argument. I need to eagerly fetch the collection, but I'm not sure how to do this. I'd like to do something like this:
Foo.withCriteria {
eq("id", someId)
bars {
eq("someDate", ?????)
}
}
I'm not sure what to put in for the value though, since it's not known ahead of time, or if there's a better way to do it?