Grails Unique Constraint for Groups
- by WaZ
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
Please let me know what to mention in my unqiue constraint to make this possible?
Thanks,
Much Appreciated.