【问题标题】:How to create a unique index using grails and mongodb?如何使用 grails 和 mongodb 创建唯一索引?
【发布时间】:2014-09-01 18:41:02
【问题描述】:
class Country{
    String id
    String code
    Set<State> states
    static embedded = ['states']
}
class State{
    String id
    String code
}

我正在尝试为国家代码 + 州代码设置唯一索引(或 gorm 约束验证)

这些不起作用:

  • 代码唯一性:约束中为真
  • 代码索引:true,indexAttributes:[唯一:true]

你能帮帮我吗?

【问题讨论】:

    标签: mongodb grails gorm-mongodb


    【解决方案1】:

    试试这个:

    class State{
        String id
        String code
        static belongsTo = [country: Country]
        static constraints = {
            code( unique: ['country'])
        }
    }
    

    【讨论】:

    • 它不起作用,如果我在命名字段中添加belongsTo(静态belongsTo = [country:Country]),grails会以无限循环崩溃...
    猜你喜欢
    • 2014-07-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-17
    • 2015-02-06
    • 1970-01-01
    • 2020-09-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多