使用GORM创建多个唯一列时出现问题 [英] An issue while creating multiple unique columns with GORM
本文介绍了使用GORM创建多个唯一列时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
class MyClass {
static auditable = true;
字符串描述;
布尔isActive = true;
日期deletedAt;
static constraints = {
description size:1..250,blank:false,unique:['deletedAt','isActive'],index:'myclass_idx'
deletedAt nullable:true,index:'myclass_idx'
isActive index:'myclass_idx'
}
}
我期望它做的是创建一个不允许重复记录的约束:
ID |描述| is_active | deleted_at
1 | desc1 | true | (null)
2 | desc1 | true | (null)
但是这个stil发生了。我在这里错过了什么?
UPD:发现只有当空值相互比较时才会发生这种情况。如果 deleted_at
包含两个相等的日期值,则约束起作用。
是否有解决方法?
解决方案 最后决定使用 deletedAt
字段的默认非空值。
I have this Grails domain class:
class MyClass {
static auditable = true;
String description;
Boolean isActive=true;
Date deletedAt;
static constraints = {
description size: 1..250, blank: false, unique:['deletedAt', 'isActive'], index:'myclass_idx'
deletedAt nullable: true, index:'myclass_idx'
isActive index:'myclass_idx'
}
}
What I expect it to do is to create a constraint which won't allow duplicate records like these:
id| description | is_active | deleted_at 1 | desc1 | true | (null) 2 | desc1 | true | (null)
but this stil happens. What am I missing here?
UPD: figured out that this happens only when there are null values compared to each other. If deleted_at
contains two equal date values, the constraint works.
Is there a workaround for that?
解决方案
Finally decided to use default not-null values for deletedAt
field.
这篇关于使用GORM创建多个唯一列时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文