5

Is there a way to use findWhere and a not equal value (trying to use it vs criterias)?

E.g.

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

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

def result = Books.createCriteria().get{
            eq('sale', true)
            ne("category", 'exclude me')
}

2 Answers 2

3

You can use either the dynamic finder methods:

Books.findAllBySaleAndCategoryNotEqual(true, 'exclude me')

or the where queries (which use DetachedCriteria:

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

I'm not aware of a way to do it with findWhere but there is a nice syntax for two-property dynamic finders where one is a boolean

Books.findSaleByCategoryNotEqual('exclude me')

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.