问题
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