Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the name of the table GORM object is mapped to?

Say I have something like:

class Foo {
    static mapping = {
        table 'foo_table'
    }
}

How can I get the name of foo_table if I have a reference to an instance of this object?

like image 299
Igor Avatar asked Oct 05 '11 16:10

Igor


1 Answers

Import org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.

To get the table name from the domain class:

def tableName = GrailsDomainBinder.getMapping(Foo).table.name 

And to get the table name from an instance of the domain class:

def tableName = GrailsDomainBinder.getMapping(foo.class).table.name
like image 167
James Allman Avatar answered Oct 25 '22 14:10

James Allman