Grails findWhere not equal

Is there a way to use findWhereand not equal value (trying to use it against the criteria)?

eg.

Books.findWhere('sale' : true, 'category': ne('exclude me') )

I have a working solution, but I was wondering if there is a way to use findWhere. I find it easier to read it.

def result = Books.createCriteria().get{
            eq('sale', true)
            ne("category", 'exclude me')
}
+5
source share
2 answers

You can use either dynamic search methods:

Books.findAllBySaleAndCategoryNotEqual(true, 'exclude me')

or where are the requests (which use DetachedCriteria:

Books.findAll {
     (sale == true) && (category != 'exclude me')
}
+3
source

I don’t know how to do this with help findWhere, but there is good syntax for dynamic crawlers with two properties, where one isboolean

Books.findSaleByCategoryNotEqual('exclude me')

(or findNotSaleBy...if you want the sale to be false).

+2
source

All Articles