我正在创建一个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列)?
答案 0 :(得分: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
}
答案 1 :(得分: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']