使用Grails 1.3.7,我将处理遗留数据库。我有一个域对象''Cake'',它在连接表中有自己的嵌入式''Ingredients''集合。
Ingredient.groovy
class Ingredient {
String name
IngredientCategory category
mapping {
table "foo_ingredient"
version false
id composite:['name', 'category']
columns {
word column:"the_name"
category column:"lol_category_id"
}
}
}
Cake.groovy
class Cake {
String name
static hasMany = [ ingredients : Ingredient ]
static mapping = {
table "foo_cake"
version false
columns {
id column:"id"
name column:"the_name"
}
ingredients joinTable: [
name : "foo_cake_ingredient",
key : "cake_id"
]
}
}
问题是,Grails希望表''foo_cake_ingredient''有两列''ingredient_name''和''ingredient_category_id''。我想手动指定那些列名,而不是让Grails(错误地)猜测那些。我无法想象如何做到这一点。
答案 0 :(得分:1)
答案 1 :(得分:0)
您可能必须为此关系中的两个表创建一个hibernate xml映射。
您是否阅读过http://jasonrudolph.com/blog/2006/06/20/hoisting-grails-to-your-legacy-db/?