Modeling many-to-many relationships in the Grail on top of an outdated database

I have a simple LAMP ticket log entry.

I am currently playing with the grail. I want to create a demo application that uses the existing MySql database without changing the database too much.

The database has a many-to-many relationship: the client table is mapped to the user table through the cliet_contact table (that is, not the standard client_user agreement).

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

Any help would be appreciated.

Thanks!

+3
source share
1 answer

joinTable , . :

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'] 
    }
}
+5

Source: https://habr.com/ru/post/1707674/


All Articles