Overriding default `maxSize` in domain class

拥有回忆 提交于 2019-12-11 06:35:26

问题


I've set a default value, for maxSize constraint, to all my domains, using

config.grails.gorm.default.constraints = {
    ...
    '*'(..., maxSize: 80)
    ...
}

Now, I want to override this value inside my domain class; I can do that by defining it there

static constraints = {
    ...
    prop maxSize: 120
    ...
}

But how could I make it unlimited, for instance?

I wish it could have been done by providing -1. Or the String and other Collections could have been handled differently, by using two different constraints; such as, maxSize or maxLength, or maxSize or maxElems.

Or

Is it possible to define default maxSize just for String types, in the first place?

Note: maxSize works for String and Collection, both. For String, defining unlimited maxSize, doesn't make much sense, due to the size limitation on database field. But Collections are used for relationships, it makes perfect sense to not have any limit here.

Edit: Somewhat, got an answer of my second question in this thread, provided in the comment; but 1st answer, there, is a workaround and not very related to my problem, I want the constraint, and 2nd answer will work, but is not to my liking.

来源:https://stackoverflow.com/questions/46481708/overriding-default-maxsize-in-domain-class

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