Skip to content

Derived Properties In Grails

As described in the grails doco, derived properties seem to be restricted to simple formulae like ‘PRICE * TAX_RATE’.

Not true, silly me!

After kneeling at the alter of The Great Google I ended up here, which put me straight. All praise The Great Google.

The following works very nicely to determine the cardinality of a given relationship:

class Practice {
    Long numDoctors

    static mapping = {
        numDoctors formula: '(select count(*) from doctor dr where (dr.practice_id = id))'

    static hasMany = [
        doctors: Doctor

Just something to remember.

Tags: , ,

C, Java Enterprise Edition, JEE, J2EE, JBoss, Application Server, Glassfish, JavaServer Pages, JSP, Tag Libraries, Servlets, Enterprise Java Beans, EJB, Java Messaging Service JMS, BEA Weblogic, JBoss, Application Servers, Spring Framework, Groovy, Grails, Griffon, GPars, GAnt, Spock, Gradle, Seam, Open Source, Service Oriented Architectures, SOA, Java 2 Standard Edition, J2SE, Eclipse, Intellij, Oracle Service Bus, OSB