【发布时间】:2013-02-18 17:13:54
【问题描述】:
Color 和 Shade 之间存在多对多关联。 Color 有多种颜色,Shades 有多种颜色。
我是这样建模的:
class Color {
static hasMany = [shades: Shade]
String name
}
class Shade {
static belongsTo = Color
static hasMany = [colors: Color]
String name
}
但是,当我运行以下代码时:
new Color(name: "Red").addToShades(new Shade(name: "light")).save()
它只将记录保存在Color 表和Shade 表中,但不保存在Color_Shades 表中,Color_Shades 表本质上是两者之间的连接表。
我做错了吗?这就是我从docs 中理解的:
【问题讨论】:
标签: grails many-to-many grails-orm