Grails query not inList
Asked Answered
R

1

7

I'm writing a criteria to make a query, but I can't figure out how to negate an inList criteria...Is there a way to do something like:

def result = c {
     not inList('id', ids)
}

Thanks

Refulgent answered 2/5, 2012 at 11:44 Comment(0)
S
19

Your criteria should like this...

def ids = [1, 2, 3];

def c = Foo.createCriteria();
def results = c.list {
  not {'in'("id",ids)}
}

The documentation can be found here. I believe this was just added in grails 2.+

Sports answered 2/5, 2012 at 12:36 Comment(2)
you're right...except for the fact that the not method doesn't seem existsRefulgent
@Refulgent Probably pointless to add, since more than 3 years have passed, but.. need to cast to array before passing (toArray()).Cas

© 2022 - 2024 — McMap. All rights reserved.