In a gorm domain class, I can do
def q = {
property1{
eq('attr', 0)
}
}
MyDomainClass.list(q)
How could I modify the closure 'q' (or create a new closure that would contain the restrictions that closure 'q' has) at runtime so for example I could add another property restriction?
More details
Actually my problem is how to create combined criteria in a Domain Class Hierarchy.
class Parent{
int pAttr
static def getCriteria(){
def dummyParentCriteria = {
eq('pAttr', 0)
}
}
}
class Child extends Parent{
int cAttr
static def getCriteria(){
def dummyChildCriteria = {
// (1)
eq('cAttr', 0)
}
}
}
In 'dummyChildCriteria' I want to avoid repeating parent's restrictions.
I would like to somehow combine the result of Parent's getCriteria there (1)
A solution with named queries inheritance
class Parent{
int pAttr
static namedQueries = {
parentCriteria{
eq('pAttr', 0)
}
}
}
class Child extends Parent {
int cAttr
static namedQueries = {
childCriteria{
parentCriteria()
eq('cAttr', 0)
}
}
}
But if someone knows the answer to the initial question it would be nice to know!