Reputation: 621
So I have 2 classes that have a many to many association. When the database gets generated I get 2 join tables: user_link_sections and link_section_users. The first I expected, but am not sure why the 2nd join table was generated. Grails is only using the first as well. I'm a noobie to groovy/grails, but tried following the documentation to set this up right. Any help is appreciated!
Here are my domain class declarations...
class User {
transient springSecurityService
// Custom Attributes
String firstName
String lastName
String email
String company
String phone
Date dateCreated
Date lastUpdated
static hasMany = [linkSections: LinkSection]
String username
String password
boolean enabled
boolean accountExpired
boolean accountLocked
boolean passwordExpired
}
and
class LinkSection {
String name
String description
Date dateCreated
Date lastUpdated
List links = new ArrayList()
static belongsTo = User
static hasMany = [links: Link, users: User]
static constraints = {
name blank: false
description(maxSize: 10000)
}
static mapping = {
links cascade: "all,delete-orphan"
}
}
Upvotes: 0
Views: 809
Reputation: 15673
Try setting the owning side of the many-many:
static belongsTo = User
this goes on the LinkSection. Remember only one side knows to persist the relationship.
The other thing to do is to make sure and clear out the tables that may have been left over from your previous attempts at mapping...just to be sure.
Upvotes: 2