0

I have a domain class People, which has multiple cars and houses:

def People {
    SortedSet<Car> cars = new TreeSet<Car>()
    SortedSet<House> houses = new TreeSet<House>()
}

def Car {
    Long id
}

def House {
    Long id
}

In grails, I would like to find people who have car with id = 1, and house with id = 1.

How do I achieve this efficiently? I have tried this but it doesn't work:

People.withCriteria {
    cars {
        inList('id', 1L)
    }
    houses {
        inList('id', 1L)
    }
}

Neither does this as it return multiple similar objects:

People.withCriteria {
    createAlias('cars', c)
    createAlias('houses', h)

    inList('c.id', 1L)
    inList('h.id', 1L)
}

Will anyone lend a hand here? Thanks!

Jay
  • 161
  • 1
  • 18
  • Shouldn't `inList` be `in`? – doelleri Jan 14 '17 at 20:49
  • Check the docs for [`createCriteria()`](http://docs.grails.org/latest/ref/Domain%20Classes/createCriteria.html) – doelleri Jan 17 '17 at 05:16
  • Oh, the doc really use `in`, perhaps I'm using different grail version, it can't compile if I use `in`. Anyway, I got this all wrong since the list is suppose to be the second parameter – Jay Jan 17 '17 at 10:17

0 Answers0