Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grails - inheritance in domain class - inherited columns into base tables

I have a Record class as :

class Record {
    Date dateCreated
    Date lastUpdated
    def beforeInsert() {
        dateCreated = new Date()
    }
    def beforeUpdate() {
        lastUpdated = new Date()
    }
    static mapping = { tablePerHierarchy false }
}

And this class is inherited by several other domain classes - for example :

class User extends Record{
    String userName
    String password
    String email
}

My question here is : Is there any way to embedd the columns of Record table into the table which extends it?

like image 217
gtiwari333 Avatar asked Feb 20 '23 20:02

gtiwari333


1 Answers

You can define tablePerClass or tablePerHierarchy strategies. See documentation here.

So, following, your code you should use:

static mapping = {
    tablePerHierarchy true
}    
like image 93
WeMakeSoftware Avatar answered Feb 26 '23 10:02

WeMakeSoftware