Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set a String with fixed length in grails constraints?

Tags:

grails

I have this domain class

class Client {
  String idCard
  ...

  static constraints = {
    idCard size:16
    ...
  }
}

I created some test data in bootstrap.groovy file

But i get the following error message

Caused by IllegalArgumentException: Parameter for constraint [size] of property [idCard] of class [class ni.sb.Client] must be a of type [groovy.lang.IntRange]

I need this property to be a String and have a fixed length

I am following size constraints documentation with no success

Thanks, for your time

like image 410
Mario Avatar asked Dec 15 '22 20:12

Mario


1 Answers

You can use

static constraints = {
    idCard maxSize:16, minSize: 16 // or simply use size: 16..16
    ...
}

This works for Strings and will affect the schema generation VARCHAR(16) (e.g. for MySQL)

like image 164
saw303 Avatar answered Feb 22 '23 19:02

saw303