如何定义域是否在grails中有多个唯一字段?

时间:2021-12-15 20:17:02

I have domain that has more than one unique fields like the following

我的域名包含多个以下的唯一字段

class Shoes{
   String name; 
   Brand brand ;
   Color color ;
   Supplier supplier ; 
   Integer size ; 
   BigDecimal price;
}

name, brand, color and supplier need to be unique ... so if there are product with same name brand color and supplier it would return false / validated as false.

名称,品牌,颜色和供应商需要是唯一的...因此,如果有同名品牌颜色和供应商的产品,它将返回false / validated为false。

is that possible to define that in grails or should i create a criteria before saving the form ? :)

可以在grails中定义,或者我应该在保存表单之前创建标准吗? :)

thank you !!!

谢谢 !!!

1 个解决方案

#1


http://grails.org/doc/1.1/ref/Constraints/unique.html

static constraints = {
   name unique: [ 'brand', 'color', 'supplier' ]
}

#1


http://grails.org/doc/1.1/ref/Constraints/unique.html

static constraints = {
   name unique: [ 'brand', 'color', 'supplier' ]
}