user903772
user903772

Reputation: 1562

Grails control join table

my alert entity has connection to these entites.. Can they all be joined into one big table? This is a one to many relationship. And not having alert_locations, alert_user,etc

class Alerts { 

    static hasMany = [locations:Locations, alertStatus:AlertStatus, users:Users]
    Date alertDateTime
    String pest
    String crop

    static constraints = {
        alertDateTime (blank:false)

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

Upvotes: 0

Views: 433

Answers (1)

Burt Beckwith
Burt Beckwith

Reputation: 75681

If you make the relationships bidirectional with an Alerts field then it will eliminate the need for join tables since it can store the foreign key to the Alerts in each table, e.g.

class Locations {
   Alerts alerts
   ...
}

You can also use the map form of belongsTo which would add cascaded deletes:

class Locations {
   static belongsTo = [alerts: Alerts]
   ...
}

Upvotes: 1

Related Questions