drago
drago

Reputation: 1207

Grails GORM collection

Lets say I have to Grails domain classes: Car and Person.

class Car {
    String model
    ...
    Person driver
}

class Person {
    String firstName
    String lastName
}

I have a set of persons:

Set < Person >

How can I get a list of all Car instances that have drivers that are in that set?

Upvotes: 0

Views: 387

Answers (1)

Jarred Olson
Jarred Olson

Reputation: 3243

So I'm assuming you have a set of person objects like so:

def people = [person1, person2, person3]

and you want to retrieve all cars that have one of the 3 drivers:

def cars = Car.findAllByDriverInList(people)

As long as the objects in the people list are instances of the Person domain you should be good to go.

Upvotes: 1

Related Questions