【问题标题】:Grails: Domain model relationships based on legacy databaseGrails:基于遗留数据库的领域模型关系
【发布时间】:2014-01-31 19:41:02
【问题描述】:

我正在创建一个 Grails 应用程序,该应用程序从现有的遗留数据库(无法修改)中获取数据,并且我正在努力思考如何在域模型类中表示表关系。

以下是一些示例数据:

Table 1 Columns: pID, FirstName, LastName, MiddleName
Table 1 ID is composite made up of pID and LastName

Table 2 Columns: pID, EmailAddress, PhoneNumber, FaxNumber
Table 1 ID is composite made up of pID, EmailAddress, PhoneNumber

Table 3 Columns: pID, Occupation
Table 3 ID is just pID

如何用域模型类表示这三个表及其关系(通过 pID 列)?

【问题讨论】:

  • 可能重复 here。尝试使用插件。
  • 我实际上使用了那个插件,但它并没有在类之间创建关系。它只是为每个表创建一个类(不考虑它如何连接到其他表)
  • 使用数据库逆向工程插件你有什么收获?将这些域类添加到问题中。

标签: grails relationship domain-model table-relationships


【解决方案1】:
class Table3{
  String id, occupation
}

class User implements Serializable{
  Table3 pID
  String firstName, lastName, middleName
  static mapping = {
        // need name maping: 
        id composite: ['pID', 'lastName']
    }
  //!!!Add equals and hashCode
}
class Profile implements Serializable{
  Table3 pID  
  String emailAddress, phoneNumber, faxNumber
  static mapping = {
        // need name maping: 
        id composite: ['pID', 'emailAddress', 'phoneNumber']
    }
  //!!!Add equals and hashCode
}

【讨论】:

    【解决方案2】:

    本教程提供了有关关系的指导: http://grails-plugins.github.io/grails-db-reverse-engineer/docs/manual/guide/4%20Tutorial.html

    6. Configure the reverse engineering process.
    
    Add these configuration options to grails-app/conf/Config.groovy:
    
    grails.plugin.reveng.packageName = 'com.revengtest'
    grails.plugin.reveng.versionColumns = [other: 'nonstandard_version_name']
    grails.plugin.reveng.manyToManyTables = ['user_role']
    grails.plugin.reveng.manyToManyBelongsTos = ['user_role': 'role', 'author_books': 'book']
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多