Ways to map and query many-to-many in GORM
I played with many-to-many relations in grails and found some interesting ways to work with them. First the domain definitions. For the purpose of this demo I chose the classic example with books and authors. A book may have many authors and an author may have many books. class Author { String name } class Book { String name } What I consider the silliest way to define your domains I found here http://www.grails.org/Many-to-Many+Mapping+without+Hibernate+XML They suggest mapping the join table using a domain object and creating the links by hand. On 'books and authors' it would look like class Book { String name static hasMany = [ memberships: Membership] List authors() { return memberships.collect {it.author} } List addToAuthors(Author author) { Membership.link(this, author) return authors() } List removeFromAuthors(Author author) { Membership.unlink(this, author) return authors() } } class Author { String name static hasM