希望我没有在您的问题中遗漏任何内容,但我已经做过这样的事情:
创建一个名为的类MyInstant
并在hasMany
import org.joda.time.Instant
class MyInstant {
Instant myInstant
//anything else you might need
}
class Foo {
MyInstant birthday
Set favoriteDays = []
static hasMany = [favoriteDays: MyInstant]
}
我已经在以下方面进行了测试FooController
:
import org.joda.time.Instant
class FooController {
def save() {
def fooInstance = new Foo(params)
.addToFavoriteDays(new MyInstant(myInstant: new Instant()))
.addToFavoriteDays(new MyInstant(myInstant: new Instant()))
.addToFavoriteDays(new MyInstant(myInstant: new Instant()))
if (!fooInstance.save(flush: true)) {
render(view: "create", model: [fooInstance: fooInstance])
return
}
flash.message = message(code: 'default.created.message', args: [message(code: 'foo.label', default: Foo'), fooInstance.id])
redirect(action: "show", id: fooInstance.id)
}
}
一切都正确保存,show
然后动作显示所有瞬间的新 Foo。我已经在 H2 和 MySql 上对此进行了测试。