Grails Unique Constraint for Groups

Posted by WaZ on Stack Overflow See other posts from Stack Overflow or by WaZ
Published on 2010-04-09T15:29:09Z Indexed on 2010/04/09 15:33 UTC
Read the original article Hit count: 209

Filed under:

Hi there, I have the following requirement
I have 3 domains namely:

        class Product {
            String productName
            static constraints = {
              productName(unique:true,blank:false)
            }

        class SubType {
            String subTypeName
            static constraints = {
            subTypeName(unique:true,blank:false)
            }

            String toString()
          {
          "${subTypeName}"
          }
    }

        class CLType {

            String TypeName
            static belongsTo = Car
            static hasMany = [car:Cars]
            static constraints = {
            }


          String toString()
          {
              "${TypeName}"

          }


class CLines implements Serializable {
    Dealer dealer
    CLType clType
    SubType subType
    Product product

    static constraints = {
       dealer(nullable:false,blank:false,unique:['subType','product','clType'])
       clType(blank:false,nullable:false)
       subType(nullable:true)
       product(nullable:true)
      }
      }

I want to achieve this combination: A user can assign dealer a CLType. But cannot have duplicates.
As an example consider this scenario alt text

Please let me know what to mention in my unqiue constraint to make this possible?

Thanks, Much Appreciated.

© Stack Overflow or respective owner

Related posts about grails