0

我正在创建一个 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 列)?

4

2 回答 2

0
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
}
于 2014-02-04T19:51:21.787 回答
0

本教程提供了有关关系的指导: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']
于 2014-02-04T19:54:57.013 回答