tags:

views:

416

answers:

1

Hi

I have a simple ticket logging application build on LAMP.

I am currently playing around with grails. I want to build a demo app that uses the existing MySql database without changing the database too much.

There is a many-to-many relationship in the database: 'client' table is mapped to the 'user' table through the 'cliet_contact' table (i.e. not the standard 'client_user' convention).

How would I translate this into grails domain classes using grail 1.1?

Any help would be appreciated.

Thanks!

+2  A: 

You can use the joinTable keyword in your mapping to specify the table name. Here's the example from that page:

class Book {
    String title 
    static belongsTo = Author 
    static hasMany = [authors:Author]
    static mapping = { 
        authors joinTable:[name:"mm_author_books", key:'mm_book_id' ] 
    }
}

class Author { 
    String name
    static hasMany = [books:Book]
    static mapping = { 
        books joinTable:[name:"mm_author_books", key:'mm_author_id'] 
    }
}
Ben Williams
Thanks BenThat is precisely what I needed!
Heinrich Filter