如何在Grails中指定hasOne属性的表名
我使用如何在Grails中指定hasOne属性的表名,grails,gorm,Grails,Gorm,我使用hasOne实现Grails中的一对一关系: class MyParent { static hasOne = [child: MyChild] } class MyChild { static belongsTo = [parent: MyParent] static mapping = { table: 'MyChild' } } 我在数据库中有一个名为“MyChild”的表,因此我得到了下一个错误: Invalid object n
hasOne
实现Grails中的一对一关系:
class MyParent {
static hasOne = [child: MyChild]
}
class MyChild {
static belongsTo = [parent: MyParent]
static mapping = {
table: 'MyChild'
}
}
我在数据库中有一个名为“MyChild”的表,因此我得到了下一个错误:
Invalid object name 'my_child'
如何在Parent
类中将关系的表名指定为“MyChild”而不是“my_child”?尝试不使用“:”
static mapping = { table "mychild"}
或使用名称标签
static mapping = { table name:"mychild" }
希望这有帮助在没有“:”的情况下尝试一下。静态映射={table“mychild”}或使用名称标签静态映射={table name:“mychild”}谢谢,Alidad,这正是问题所在!:)