问题
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?
回答1:
Finally decided to use default not-null values for deletedAt
field.
来源:https://stackoverflow.com/questions/15218062/an-issue-while-creating-multiple-unique-columns-with-gorm