I have a problem with describe DB structure into my domain classes with such DB structure
ERD
http://i.stack.imgur.com/LgwQf.png
With other domains this works, but it's more simple, no such many relation one-to-many in one table. But with in this case I got error.
What I have
user can have many song list, for this I created middle table and in this table I added field with access type as id from table access_type, which have some type (all, friend etc.)
Thank you.
ERD
http://i.stack.imgur.com/LgwQf.png
With other domains this works, but it's more simple, no such many relation one-to-many in one table. But with in this case I got error.
has_access [has_access_id])) must have same number of columns as the referenced primary key (has_access [user_id,song_list_id])
What I have
user can have many song list, for this I created middle table and in this table I added field with access type as id from table access_type, which have some type (all, friend etc.)
Code:
class AccessType {
static hasMany = [hasAccess: HasAccess]
String type
static mapping = {
hasAccess joinTable:[name:'has_access', key:'access_type_id']
}
}
class HasAccess {
static belongsTo = [AccessType, SongList, User]
static constraints = {
id composite: ['song_list_id', 'user_id']
}
}
class User {
transient springSecurityService
static hasMany = [songList: SongList, hasAccess: HasAccess]
..
static mapping = {
password column: '`password`'
songList joinTable:[name:'has_access', key:'user_id']
}
}
class SongList {
static belongsTo = [Song, User]
static hasMany = [songs: Song, users: User, hasAccess: HasAccess]
String title
Date created
Date updated
static mapping = {
songs joinTable:[name:'has_song', key:'song_list_id']
users joinTable:[name:'has_access', key:'song_list_id']
}
}
Thank you.