Skip to content

What I Learned Today: Constraining Relation Cardinality In GORM

I wanted to set a limit for how many classes a Grails Domain class could relate to and I couldn’t see how to do it, so I put a call for help out on the Grails user list (user@grails.codehaus.org).

Burt Beckwith () showed me how:

class Author {
  static hasMany = [ books : Book ]
  String name
  static constraints = {
    books size: 0..3
  }
}

class Book {
  String title
}

Burt also pointed me to the doco: http://grails.org/do … onstraints/size.html.

Thanks, Burt!

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