关于这个question,有这组Grails domain
类:
class Hero {
String name
Float level
static hasOne = [familiar: Familiar]
}
class Familiar {
String name
Integer raceId
static belongsTo = [hero: Hero]
}
如何更改查询Hero
的结果:
[
name: "Emphraim",
level: 99.0,
familiar: {
name: "Mhyrr",
raceId: 1
}
]
到一个扁平的:
[
{
"name": "Ephraim"
"level": 99.0,
"familiar_name": "Mhyrr"
"familiar_raceId": 1
}
]
没有将它逐个映射到新的HashMap
?我使用以下代码查询Hero
类:
def hero = Hero.find {
eq("name", "Ephraim")
}