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

これら 3 つのテーブルとそれらの関係 (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 に答える