Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grails findWhere not equal

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')
}
like image 624
Nix Avatar asked Mar 18 '13 15:03

Nix


1 Answers

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')
}
like image 69
codelark Avatar answered Sep 28 '22 10:09

codelark