![](/img/trans.png)
[英]Problem mapping Grails Domain class to legacy database with TEXT field
[英]grails joinTable with legacy database
我有一個要用grails進行的一對多表映射。 我有一個舊數據庫,無法更改表結構。 我已經完成了所有的設置,但是我唯一不知道的是如何使grails注意到現有的外鍵而不是創建它自己的列。 我有這樣的東西(簡體):
class Customer {
String listID
String name
String address
// more fields etc.
static hasMany [notes : Note]
static mapping = {
table name:"customers"
id name:"listID",generator:"assigned"
// doesn't work, creates a foreign key column in customer_notes table
// with key: customer_id. I want it to just use the existing column
// CustomerListID, which has the correct foreign key
notes joinTable:[name:"customer_notes",key:"CustomerListID"]
}
}
class Note {
String noteID
String customerListID
static mapping = {
table name:"customer_notes"
id name:"NoteID",generator:"assigned"
}
}
附帶說明一下,我看到grails文檔中的joinTable表示“列”是反列,而“ key”是外鍵。 文檔中的示例沒有幫助。 我有“ Grails in Action”,它說它將提供一個一對多的示例,然后顯示一個很多的示例,而這兩種方式似乎都不是一個完整的示例(缺少一半的模型) !
有任何想法嗎? 我有這個舊數據庫,我將以只讀方式使用它。 我只希望O / R映射器將所有內容很好地掛鈎。
客戶域對象中的joinTable應該使用列,而不是鍵:
notes joinTable:[name:"CustomerNotes",column:"CustomerListID"]
同樣,名稱:應該是聯接表的名稱,而不是注釋表的名稱。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.