Search code examples
grailsgroovygrails-ormjoin

Grails Join Table column name


My Alert has many Location objects, and I have the join table alert_locations.

The generated columns are:

alerts_locations_id (I want this to be alert_id)

location_id

Here's my domain object:

class Alerts { 

    static hasMany = [locations:Locations,notifications:Notifications]

    Date alertDateTime
    String pest
    String crop

    static constraints = {
        alertDateTime (blank:false)

        pest (blank:false)
        crop (blank:false)
    }
}

Solution

  • static mapping = {
        locations joinTable:[column:"location_id", key:"alert_id"]