惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
Hugging Face - Blog
Hugging Face - Blog
博客园 - 聂微东
量子位
S
SegmentFault 最新的问题
V
Visual Studio Blog
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
Stack Overflow Blog
Stack Overflow Blog
Vercel News
Vercel News
D
Docker
J
Java Code Geeks
博客园 - 三生石上(FineUI控件)
博客园 - Franky
Recent Announcements
Recent Announcements
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MongoDB | Blog
MongoDB | Blog
D
DataBreaches.Net
Y
Y Combinator Blog
云风的 BLOG
云风的 BLOG
V
V2EX

博客园 - 页面载入出错

Grails指南摘要-403-生命周期 Grails指南摘要-402-logging Grails指南摘要-401-Controller中设置默认Action Grails指南摘要-307-测试领域类 Grails指南摘要-306-嵌入式对象 Grails指南摘要-304-对象关系 Grails指南摘要-303-自定义对象映射 Grails指南摘要-302-瞬时属性 Grails指南摘要-301-属性验证 20130527-jQuery in actin-看代码说事-ch01 20130518-Grails In Action-5、控制应用程序流(04小节) 20130518-Grails In Action-5、控制应用程序流(03小节) 20130517-Grails In Action-5、控制应用程序流(02小节) 20130517-Grails In Action-5、控制应用程序流(01小节) 20130517-Grails In Action-4、让模型工作(06小节) 20130516-Grails In Action-4、让模型工作(05小节) 20130516-Grails In Action-4、让模型工作(04小节) 20130516-Grails In Action-4、让模型工作(03小节) 20130516-Grails In Action-4、让模型工作(02小节)
Grails指南摘要-305-扩展和继承
页面载入出错 · 2013-06-04 · via 博客园 - 页面载入出错

多个domain继承自同一个对象

class Person {
    String frstName
    String lastName
    Integer age
}
class Employee extends Person {
    String employeeNumber
    String companyName
}
class Player extends Person {
    String teamName
}

生成的关系为一张表,可以在表中增加一个鉴别字段区分哪条记录是employee,哪条是player,这种方式称为鉴别器识别

class Employee extends Person {
    String employeeNumber
    String companyName
    static mapping = {
        // the value of the discriminator column for 
        //Employee instances should be 'working people'
        discriminator 'working people'
    }
}

还可以用整数来识别,用关系方式设计表会常用这种方式,鉴别器中42代表employee

class Employee extends Person {
    String employeeNumber
    String companyName
    static mapping = {
        discriminator value: '42', type: 'integer'
    }
}

用对象的方式更加直观,把继承关系设置成多个one-to-one对象,分别放在不同的关系表中存放

class Person {
    String frstName
    String lastName
    Integer age
    static mapping = {
        tablePerHierarchy false
    }
}