0

用 grails 做这样的事情的正确方法是什么:

class myDomainThing {
  String description
  MyOtherDomainThing otherThing

  static constraints = {
    description(nullable:if(otherThing))
    otherThing(nullable:if(description))
  }
}

所以我要么希望有一个指向 otherDomainThing 的链接,要么我想要一个字符串描述。

4

2 回答 2

2

您必须使用验证器使用 Grails 自定义 验证

static constraints = {
  description(validator: {
        return otherThing and !description
    })
}
于 2011-05-06T21:19:47.437 回答
0

您需要使用自定义验证器

static constraints = {
  description validator: { val, obj -> 
     if(otherthing && val) {
         false
     }
     else {
       true
     }
  }
}

显然那里有一些伪代码otherthing

于 2011-05-06T21:14:38.553 回答