0

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”?

4

1 回答 1

2

试试不带':'。

static mapping = { table "mychild"} 

或使用名称标签

static mapping = { table name:"mychild" }

希望这可以帮助

于 2013-03-22T19:26:06.290 回答