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}"
}
}
分享到:
相关推荐
总之,"grails-datastore-gorm-plugin-support-2.0.4.RELEASE.zip"提供了一个宝贵的资源,让开发者有机会学习和实践Grails的ORM功能和Android的MVC设计模式。无论是对Grails框架的探索,还是对Android开发的深化,这...
达梦数据库gorm驱动_gorm-driver-dm
spring-boot-starter-batch-web.zip,批量web应用程序的启动程序
the gnustep-msys-system package
Gorm转接器 在v3.0.3中,方法NewAdapterByDB创建名为casbin_rules表, 之后...go get github.com/casbin/gorm-adapter/v3 简单的例子 package main import ( "github.com/casbin/casbin/v2" gormadapter "github.com
gorm_generate Gorm模型自动生成支架帮手: -config string Special config file, format: .yml -connection string DB connect dns -dao string The directory of dao generate. -model-directory string Generated...
标题 "grails-datastore-gorm-tck-1.0.9.RELEASE.zip" 提供的信息表明,这是一个与Grails框架相关的数据存储(Datastore)和GORM(Grails Object Relational Mapping)测试兼容性工具包(Test Compatibility Kit,...
提供的文件“Gorm-1.2.10-setup.exe”是Windows平台上的安装程序,用于在Windows系统上设置和运行Gorm IDE。 Objective-C的IDE通常包含以下关键特性: 1. **代码编辑器**:Gorm提供了语法高亮、自动完成和代码折叠...
$ go get github.com/sunary/gorm-bulk-insert 这个库依赖于 gorm,除非你已经安装了 gorm,否则下面的命令也是必要的。 $ go get github.com/jinzhu/gorm 用法 批量插入 bulk . BulkInsert ( db , bulkData ) /...
开源项目-jinzhu-gorm#association-mode.zip,Even easier to handle relationships, try out gorm's Association Mode