2

Is it possible to use an 'in' criteria in a Grails DetachedCriteria?

This is what I have,

def query = new DetachedCriteria(DomainObject)

// list is actually built up from another query, 
// but for this example I will use a predefined list
query.where { 'in' 'id', [4L, 5L, 9L] }

def count = query.count()

What I am seeing is that the count, which you would expect to be 3, is actually just the entire DomainObject table.

How do I get this query to work?

James McMahon
  • 48,506
  • 64
  • 207
  • 283

1 Answers1

2

Try assigning the result of where to a query:

query = query.where { 'in' 'id', [4L, 5L, 9L] }
James McMahon
  • 48,506
  • 64
  • 207
  • 283
Elias Dorneles
  • 22,556
  • 11
  • 85
  • 107
  • You can also write it as, `query = query.where { 'id' in [4L, 5L, 9L] }`, though I am not sure if that changes the performance of the query at all – James McMahon May 11 '13 at 16:46