I have class named User and another one named Role and they are
related to each other in a many-to-many way, a user has many roles and
in a role there are many users
Besides the user and role tables I get another table named role_user
which has only two fields: roles_id and users_id
roles_id refers to the field id in the table user, and
users_id refers to the field id in the table role.
class Role {
static hasMany = [users : User]
String name
Date dateCreated
Date lastUpdated
static mapping = {
columns {
users column:'roles_id'
}
}
static constraints = {
name(blank:false)
dateCreated()
lastUpdated()
}
String toString() {
"${id}-${this.name}"
}
}
class User {
static belongsTo = [Role]
static hasMany = [roles : Role]
String login
Date dateCreated
Date lastUpdated
static mapping = {
columns {
roles column:'users_id'
}
}
static constraints = {
login(length:6..30, unique:true)
dateCreated()
lastUpdated()
}
String toString() {
"${id}-${this.login}"
}
}
分享到:
相关推荐
GORM还支持不同类型的关联,如一对一(One-to-one)、一对多(One-to-many)和多对多(Many-to-many)关系,允许在领域模型之间建立复杂的关系。 在并发控制方面,Groovy和Grails提供了乐观锁和悲观锁的概念。乐观...
Grails的设计理念是“约定优于配置”(Convention Over Configuration),简化了开发流程,使开发者能够更加专注于业务逻辑而非繁琐的配置工作。 #### 二、入门指南 ##### 2.1 下载与安装 - **下载地址**:Grails...
毕业设计基于单片机的智能循迹小车分析.doc
云技术基础与虚拟化应用实战解析培训课件.pptx
计算机考试选择题.docx
【目标检测】半导体晶圆缺陷数据集waferMap数据集13000张9类.docx
电子商务实验三网站分析与设计蔬菜批发网.doc
计算机网络课程考试复习.doc
系统集成项目管理工程师试题库.docx
计算机二级考试复习软件工程基础.doc
自动化专业知识体系.doc
电子商务培训方案.docx
电子商务门户网站方案.doc
计算机技能竞赛的总结.docx
软件发布管理系统流程要求规范.doc
网络规划与组建实训指导.doc
系统集成项目管理工程师考前模拟试题及答案.doc
第五版项目管理过程组与知识领域表格.doc
计算机应用基础国家开放大学模块五.doc
短距离无线通信技术.doc