这些是我的域类
GameCategory.groovy
class GameCategory {
String categoryName
String icon
String toString(){
"${categoryName}"
}
static hasMany = [ list:GameList]
static constraints = {
}
Game.groovy
class Game {
String gameTitle
float gamePrice
String gameDescription
Date releaseDate
float rating
int numberOfRaters
int numberOfReviews
String toString(){
"${gameTitle}"
}
static hasMany = [list : GameList ]
static constraints = {
}
GameList.groovy
class GameList {
static belongsTo = [game : Game , category : GameCategory]
static constraints = {
}
我的问题是,如何在给定类别作为参数的情况下检索游戏的所有实例我无法理解hasMany和belongsTo in grails
答案 0 :(得分:1)
GameList.findAllByCategory(myCategory).collect{it.game}
使用createCriteria可能会使其变得更复杂,但您必须使用别名加入,代码将变得更加复杂。