0
votes

These are my domain class

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 = {
}

My question is, how do I retrieve all instance of a game given a category as parameter I'm having trouble understanding the hasMany and belongsTo in grails

1

1 Answers

1
votes
GameList.findAllByCategory(myCategory).collect{it.game}

You could make it more complicated by using createCriteria but then you have to join with an alias and the code will become more complicated.