Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Grails:基于遗留数据库的域模型关系_Grails_Relationship_Domain Model_Table Relationships - Fatal编程技术网

Grails:基于遗留数据库的域模型关系

Grails:基于遗留数据库的域模型关系,grails,relationship,domain-model,table-relationships,Grails,Relationship,Domain Model,Table Relationships,我正在创建一个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

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

本教程提供了有关关系的指导:
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
}


可能重复。尝试使用这个插件。我实际上使用了这个插件,但它不会在类之间创建关系。它只是为每个表创建一个类(不考虑它如何连接到其他表),您使用数据库反向工程插件得到了什么?将这些域类添加到问题中。
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']