Skip to content

Instantly share code, notes, and snippets.

@yuki-takei
Created April 13, 2014 00:12
Show Gist options
  • Save yuki-takei/10563186 to your computer and use it in GitHub Desktop.
Save yuki-takei/10563186 to your computer and use it in GitHub Desktop.
MongoDB GORM - Inheritance mapping Tips ref: http://qiita.com/yuki-takei/items/2b173dea5c45de44fcb8
abstract class AbstractUser {
static mapWith = "mongo"
static mapping = {
name index: true
}
static constraints = {
desc nullable: true
}
String name
String desc
def beforeInsert() {
doSomething()
}
def afterLoad() {
doSomething()
}
}
class ActiveUser extends User {
static mapping = {
collection "activeUser" // 無視される
}
}
"_class": "ActiveUser",
"_class": "ActiveUser",
class InactiveUser extends User {
static mapping = {
collection "inactiveUser" // 無視される
}
}
class User {
static mapWith = "mongo"
static mapping = {
collection "user"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment