I'm kinda new to Grails so I need help with this matter. Imagine I have these classes:
Class User{
String name
String nr
}
class Computer{
String processor
String ram
User user
}
Class Room{
String roomNr
Computer computer
}
I want to do a controller like this:
def print= {
def user = User.get(1)
def computer = Computer.findAllByUser(user) // all computers filtered by User
[computer: computer]
}
The controller works good, but I want to be able to pass not only the computer instances, but also the Room's with that computer id's. I dont know how to do it, but would be something like this (same controller, same action):
def print= {
def user = User.get(1)
def computer = Computer.findAllByUser(user) // all computers filtered by User
def room = Room.findAllByComputer(computer) ##
[computer: computer]
}
Well, this is wrong because, where the ### is, 'computer' represents a list of id's and not a single id. As I am passing a list of computers to be printed in my gsp inside a g: each tag like this: (it. Processor, it. Ram). I dont know how to get all the rooms which are using the current computer in the each tag. This is a bit hard to explain, but basically my output would be:
<g:each in="${computer}"
Computer1:
Processor: ${it.processor}
Ram: ${it.ram}
Room: ????? (How to get here??)
</g:each>