سؤال

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?

هل كانت مفيدة؟

المحلول

Try this

class Person extends AbstractDomain {
    String name
    Integer age

    static namedQueries = {
        age18 {
            eq("age", 18)
            }
        } << AbstractDomain.namedQueries
    }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top