如何解决http://jira.grails.org/browse/GPJODATIME-28阻止域类拥有任何扩展类型的hasMany的问题? 我正在考虑将整个应用程序切换为持久化来自BigDecimal的自定义UserType以用于posix纪元日期。虽然看起来像锤子的核桃。我可以采取另一种方法吗?
import org.joda.time.Instant
class Foo {
Instant birthday
Set favoriteDays = []
static hasMany = [
favoriteDays : Instant
]
static constraints = {
}
}
答案 0 :(得分:0)
希望我在你的问题中没有遗漏任何东西,但我做过这样的事情:
创建一个名为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上测试了这个。