посмотрите на http://www.grails.org/Many-to-Many+Mapping+without+Hibernate+XML (я думаю, что это актуально).
знать: http://codedumpblog.blogspot.com/2010/02/grails-many-to-many-with-lists.html
приведенный ниже код работает для меня, используя grails 1.2.0. но, похоже, мне пришлось сделать много save (). не забудьте сделать контроллеры и установить scaffold = domain_class
package p
class Company {
String toString() { "$name"
}
static hasMany=[roles:Role]
static constraints = {
}
String name
}
package p
class Role {
String toString() { "$name"
}
static belongsTo=[company:Company]
static hasMany=[personRoleAssociations:PersonRoleAssociation]
static constraints = {
}
String name
}
package p
class Person {
String toString() { "$name"
}
static hasMany=[personRoleAssociations:PersonRoleAssociation]
static constraints = {
}
String name
}
package p
class PersonRoleAssociation {
String toString() { "${person.name} as ${role.name}"
}
static belongsTo=[person:Person,role:Role]
static constraints = {
}
}
import p.*
class BootStrap {
def init = { servletContext ->
Person dick=new Person(name:'dick')
Person jane=new Person(name:'jane')
dick.save()
jane.save()
Company ibm=new Company(name:'ibm')
ibm.save()
Role ibmManager=new Role(name:'ibmmanager')
Role ibmPeon=new Role(name:'ibmpeon')
ibm.addToRoles(ibmManager)
ibmManager.save()
ibm.addToRoles(ibmPeon)
ibmPeon.save()
ibm.save()
Company sun=new Company(name:'sun')
sun.save()
Role sunManager=new Role(name:'sunmanager')
Role sunPeon=new Role(name:'sunpeon')
sun.addToRoles(sunManager)
sunManager.save()
sun.addToRoles(sunPeon)
sunPeon.save()
sun.save()
PersonRoleAssociation dickManager=new PersonRoleAssociation()
dick.addToPersonRoleAssociations(dickManager)
ibmManager.addToPersonRoleAssociations(dickManager)
PersonRoleAssociation dickPeon=new PersonRoleAssociation()
dick.addToPersonRoleAssociations(dickPeon)
sunPeon.addToPersonRoleAssociations(dickPeon)
PersonRoleAssociation janeManager=new PersonRoleAssociation()
jane.addToPersonRoleAssociations(janeManager)
sunManager.addToPersonRoleAssociations(janeManager)
PersonRoleAssociation janePeon=new PersonRoleAssociation()
jane.addToPersonRoleAssociations(janePeon)
ibmPeon.addToPersonRoleAssociations(janePeon)
}
def destroy = {
}
}