Search code examples
listgrailsgroovyfindby

Can I use IN and findBy together in Groovy and Grails?


I've been trying to figure out how to do something like

SELECT * FROM domain WHERE config_id IN (1, 2, 3)

when using the nice findBy technique of Grails. Haven't really figured out how yet though, is it even possible? I was hoping for something like

Domain.findByConfigIn(configList)

but that doesn't work. Anyone knows how to do this, or even if it's possible?


Solution

  • Assuming your domain class has a field named configId, the following should do what you want:

    Domain.findAllByConfigIdInList(configList)