【问题标题】:domain class constraint in entry creation条目创建中的域类约束
【发布时间】:2015-02-25 15:00:06
【问题描述】:

在我的 Grails 项目中,我需要将特定的约束添加到我的域类对象的条目中。 域类如下:

class HealthServiceType {
   String healthService;
   static belongsTo = [doctor:Doctor]
   static constraints = {

   }

   static mapping = {

   }
}

我需要 healthService 不是空的,并且对于每个 Doctor 都是唯一的;也就是说,我可以为 healthService 设置多个“测试”值,但每个需要有不同的 Doctor 值。

是否可以在域类中执行此约束?还是我需要在 Controller 中实现一些检查?

【问题讨论】:

    标签: grails constraints grails-domain-class grails-controller


    【解决方案1】:

    创建一个独特的属性非常简单。例如:

    static constraints = {
      healthService(unique: ['doctor'])
    }
    

    以上将确保healthService 的值对于您的域类中doctor 的每个值都是唯一的。

    【讨论】:

      猜你喜欢
      • 2012-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多