Reduce size of hasMany property of type String

Grails follows MVC(Model View Controller) design pattern and domain classes fulfills the M in MVC. Each domain class mapped with a table in the database, i.e., a domain class represents a table in the database.

hasMany defines a one-to-many association between two classes, eg.,

here we define a one-to-many relationship between Person and Address classes where one Person has many Address.

We can also use String, Integer, etc for hasMany association, like

here grails create a join table Person_Names having a column Names_String with type VARCHAR and size 255.

But what if we need small amount eg. 32 characters only. Then it is useless to assign 255 characters size for names.

We can solve this problem by using joinTable in mapping, like

here only 32 characters length is assigned to the names.

Hope this helps 🙂 .