An issue while creating multiple unique columns with GORM

冷暖自知 提交于 2019-12-12 05:26:20

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!