tags:

views:

65

answers:

1

Is it possible to set the database column type of a hasMany association to a primitive type (in my case string) to a specific value? I know how to set a field (see this question), but this is different.

  List textRecords
  static hasMany = [
          textRecords:String,
  ]

I want to make sure that my textRecords are mapped to a TEXT or LONGTEXT database type.

I could create a separate domain class that contains just one string field and map that field, but that seems like a kluge.

+1  A: 

The Grails User Guide has an example listed in 5.2.1.4 Basic Collection Types section that is very similar to what you want to accomplish.

Keep in mind that every time you want to add a textRecord to that object it will have to load the entire List of textRecords in order to save it again. This may not be the behaviour that you want for performance reasons.

You'll end up having a mappings block like this:

static mapping = {
       hasMany joinTable:[name:'bunch_o_text_records', key:'domain_id', column:'text_record', type:"text"]       
}
Colin Harrington