I have two domains that have a many-to-many relationship. Example:
class LibraryUser {
String name
static hasMany = [ checkedoutBooks : Book ]
}
class Book {
String title
static hasMany = [ usersWhoCheckedItOut : LibraryUser ]
}
However I now want to record the time of checkout and store this in the already existing join table:
class Checkouts {
LibraryUser user
Book book
Date dateCreated
}
class LibraryUser {
String name
static hasMany = [ checkedoutBooks : Book ]
static mapping = {
checkedoutBooks joinTable: [
name:'checkouts',
key:'libraryuser_id',
column:'book_id'
]
}
}
class Book {
String title
static hasMany = [ usersWhoCheckedItOut : LibraryUser ]
static mapping = {
usersWhoCheckedItOut joinTable: [
name:'checkouts',
key:'book_id',
column:'libraryuser_id'
]
}
}
However what I get is a checkouts table where the id
column is not set to auto_increment
(instead the libraryuser_id
is set to auto_increment
which is definitely not making any sense in my case). I suspect there is a bug somewhere in my above code?