Question

i have a question about the inheritance possibilities of named queries. We would like to store some named queries in our abstract domain class like this.

abstract class AbstractDomain {
    boolean state

    static namedQueries = {
        isActive{
            eq("state", true)
        }
    }
} 

class Person extends AbstractDomain {
    String name
    Integer age

    static namedQueries = {
        age18 {
            eq("age", 18)
        }
    }
}

When we try to call the namedquery in Abstract domain it fails due to the fact that the closure block is overridden.

Person.isActive.age18 fails due to isActive not being present.

Can we reuse named queries in the Abstract Domain class?

Was it helpful?

Solution

Try this

class Person extends AbstractDomain {
    String name
    Integer age

    static namedQueries = {
        age18 {
            eq("age", 18)
            }
        } << AbstractDomain.namedQueries
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top