我有一箇舊的數據庫,我不能改變的,我有這樣的設置如何避免ImprovedNamingStrategy在joinTable Grails中
class Foo {
static hasMany = [bars:Bar]
static mapping = {
version false
columns {
id column: "FooId"
color column: "FooColor"
bars joinTable: [name: "FooBar", key: 'FooId', column: 'BarId']
}
transient
def getBarName(){
((Bar)this.bars.toArray()[0]).name
}
}
class Bar {
static hasMany = [foos:Foo]
static belongsTo = [Foo, Baz]
static mapping = {
version false
columns {
id column: "BarId"
name column: "BarName"
}
}
當我嘗試在控制器休眠訪問方法getBarName()的翻譯反向列名稱爲「bar_id」。有沒有辦法像id和property欄一樣設置映射?
並在旁註。我如何正確實現getBarName()? Thacan't可能是正確的實現......
* 編輯 *
------------------------- ---------------------------------------------
顯然我上面還不清楚。問題是,我已經有了它的形式,因爲我想避免的joinTable域對象
-------------------
|RowId|FooId|BarId|
-------------------
| 1 | abc | 123 |
-------------------
Benoit的答案是不是真的適用於這種情況下,連接列。
* EDIT 2 *
----------------------------------- -----------------------------------
解決了它。雖然不明白...但拆分兩個域類之間的連接表信息和它的作品...
class Foo {
static hasMany = [bars:Bar]
static mapping = {
version false
columns {
id column: "FooId"
color column: "FooColor"
bars joinTable: [name: "FooBar", key: 'FooId']
}
transient
def getBarName(){
((Bar)this.bars.toArray()[0]).name
}
}
class Bar {
static hasMany = [foos:Foo]
static belongsTo = [Foo, Baz]
static mapping = {
version false
columns {
id column: "BarId"
name column: "BarName"
bars joinTable: [name: "FooBar", key: 'BarId']
}
}
這不回答這個問題。請參閱編輯進行澄清 – Spade