Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing two columns in a Grails criteria builder?

How would I go about converting Grails where syntax comparing two properties, for example,

where { prize > entryFee }

Into Grails CriteriaBuilder syntax comparing the values of two columns?

Something like,

def c = Tournament.createCriteria()
def results = c {
   gt 'prize', tournament.entryFee
}
like image 416
James McMahon Avatar asked Mar 11 '14 20:03

James McMahon


1 Answers

There are *Property nodes you can use in the criteria for comparing two properties.

In your case, you'd want something like:

def c = Tournament.createCriteria()
def results = c {
    gtProperty 'prize', 'entryFee'
}

There are also geProperty, eqProperty, neProperty, ltProperty and leProperty for greater than equal, equal, not equal, less than, and less than equal, respectively.

like image 124
doelleri Avatar answered Nov 15 '22 22:11

doelleri