`
boogie
  • 浏览: 237384 次
  • 性别: Icon_minigender_1
  • 来自: 宁波
社区版块
存档分类
最新评论

GORM many-to-many namimg convention

阅读更多

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-datastore-gorm-plugin-support-2.0.4.RELEASE.zip"提供了一个宝贵的资源,让开发者有机会学习和实践Grails的ORM功能和Android的MVC设计模式。无论是对Grails框架的探索,还是对Android开发的深化,这...

    达梦数据库gorm驱动_gorm-driver-dm.zip

    “达梦数据库gorm驱动_gorm-driver-dm.zip”这一文件是一个特定于达梦数据库的GORM驱动程序压缩包。驱动程序是软件程序的一部分,它能够使某个应用程序与硬件设备或外围设备进行通信,这里的“驱动”指的是使GORM...

    gorm-hibernate4-spring-boot-1.0.0.RC4.zip

    spring-boot-starter-batch-web.zip,批量web应用程序的启动程序

    gorm-1.2.20-2

    the gnustep-msys-system package

    gorm-adapter:适用于Casbin的Gorm适配器

    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模型存储库dao生成支架

    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-tck-1.0.9.RELEASE.zip" 提供的信息表明,这是一个与Grails框架相关的数据存储(Datastore)和GORM(Grails Object Relational Mapping)测试兼容性工具包(Test Compatibility Kit,...

    Objective-C语言IDE工具 Gorm-1.2

    提供的文件“Gorm-1.2.10-setup.exe”是Windows平台上的安装程序,用于在Windows系统上设置和运行Gorm IDE。 Objective-C的IDE通常包含以下关键特性: 1. **代码编辑器**:Gorm提供了语法高亮、自动完成和代码折叠...

    gorm-bulk-insert:使用gorm实现BulkInsert

    $ 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

    开源项目-jinzhu-gorm#association-mode.zip,Even easier to handle relationships, try out gorm's Association Mode

Global site tag (gtag.js) - Google Analytics