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

前端 未结 2 1064
不思量自难忘°
不思量自难忘° 2021-02-07 07:38

Say I have something like:

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

How can I get the name of foo_table

2条回答
  •  萌比男神i
    2021-02-07 08:35

    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
    

提交回复
热议问题