【问题标题】:save a same value using unique constraint with different foreign key id in grails在grails中使用具有不同外键ID的唯一约束保存相同的值
【发布时间】:2014-05-12 11:59:42
【问题描述】:

我有一个名为 Thana 的域,我将thanaName 与区域的父 ID 一起保存在其中。我对thanaName 使用了唯一约束。当我用一个名字保存thana时,假设'Thana A'的区域外键值为1,它被保存了。当我想用区外键值 2 再次保存“Thana A”时,由于唯一约束,它不会保存它。但我需要这样做,因为尽管thanaName 相同,但这里的地区不同。任何人都可以请帮我吗?非常感谢。

    class Thana {

    String thanaName
    District district

    static constraints = {
        thanaName unique: true // each instance must have a unique name.
    }

    static mapping = {
        table('thana')
        version(false)
        district column: 'district_id'
    }
}

【问题讨论】:

  • 这里不是很清楚你在问什么,但是如果你发布你的域类可能会让事情更清楚。
  • 这个问题和上一个问题有什么不同?
  • @JoshuaMoore 我已经编辑并发布了我的thana 域。没事吧?
  • @JoshuaMoore 非常感谢。在您的上一个问题中已回答。我没有注意到。对不起。

标签: grails grails-2.0 grails-domain-class


【解决方案1】:

您可以使用多列唯一约束,这里是文档的链接:

Unique

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-06
    • 2021-11-05
    • 1970-01-01
    • 1970-01-01
    • 2017-11-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多