I have a M:M relationship between User and Badge which creates a join table called "user_badges". This table has the fields: user_id and badge_id. Is there a way to get the standard date_created fields on this table?
class Badge {
static belongsTo = User
static hasMany = [users: User]
}
class User {
static hasMany = [badges: Badge]
}
Basically, you need to change the mapping so that the M:M relationship is expressed as two 1:M relationships. Here's an example where the joining class is BadgeOwner
(so by default the generated join table will be named badge_owner
)
class Badge {
static hasMany = [owners: BadgeOwner]
}
class User {
static hasMany = [owners: BadgeOwner]
}
class BadgeOwner {
static belongsTo = [user: User, badge: Badge]
Date dateCreated
Date lastUpdated
}
If it has additional properties, it's not a join table. It's a separate entity. So, map it accordingly :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With