Search code examples
mysqlgrailsscaffoldingcomposite-primary-key

Scaffold MySQL table with composite primary key in Grails


package website

class Translations {

    String content;

    /* Primary key consists of language_id and text_id */

    static constraints = {
        content();
    }

}

Everything is clear for tables with single primary keys.

But I wonder how to handle with composite keys.

Is it possible to scaffold those tables, using Grails 2.1.1?


Solution

  • It's directly supported, though there are some additional requirements for your domain class. See the GORM documentation at http://grails.org/doc/latest/guide/GORM.html#compositePrimaryKeys