Grails GORM:绝妙的地图
具有以下域类:
class Word {
Map translations
static hasMany = [translations: String]
String toString(){
id
}
}
并且一些实例保存在 grails bootstrap 中:
def word1 = new Word(translations: [en:"game"]);
word1.save(failOnError: true, flush: true)
def word3 = new Word(translations: [en:"gate"]);
word3.save(failOnError: true, flush: true)
def word2 = new Word(translations: [en:"life"]);
word2.save(failOnError: true, flush: true)
无法正确获取 translations
字段。例如:
//input
println Word.findAll().each {
println it.translations
}
//output
[:]
[:]
[:]
[1, 2, 3]
怎么了?
Having the following domain class:
class Word {
Map translations
static hasMany = [translations: String]
String toString(){
id
}
}
And some instances saved in grails bootstrap:
def word1 = new Word(translations: [en:"game"]);
word1.save(failOnError: true, flush: true)
def word3 = new Word(translations: [en:"gate"]);
word3.save(failOnError: true, flush: true)
def word2 = new Word(translations: [en:"life"]);
word2.save(failOnError: true, flush: true)
It's not enabled to get translations
field correctly. For example:
//input
println Word.findAll().each {
println it.translations
}
//output
[:]
[:]
[:]
[1, 2, 3]
What's wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
文档说:
如果你想要一个字符串/值对的简单映射,GORM 可以使用以下命令映射它:
The doc says:
If you want a simple map of string/value pairs GORM can map this with the following:
它应该
代替
It should be
instead of