Created
October 2, 2014 17:57
-
-
Save jeffscottbrown/865eb7637c68a90838cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person { | |
String firstName | |
Integer age | |
} | |
Person.withSession { | |
new Person(firstName: 'Jeff', age: 44).save() | |
new Person(firstName: 'Betsy', age: 43).save() | |
new Person(firstName: 'Zack', age: 17).save() | |
new Person(firstName: 'Jake', age: 14).save() | |
} | |
def firstResults = Person.where { | |
firstName =~ 'J%' && age > 20 | |
}.list() | |
def c = { | |
firstName =~ 'J%' && age > 20 | |
} | |
def secondResults = Person.where(c).list() | |
// both of these assertions pass... | |
assert firstResults.size() == 1 | |
assert secondResults.size() == 4 |
http://stackoverflow.com/users/973339/evanwong has asserted that those queries should return the same results, but they shouldn't.
The incorrect answer at the link above has since been deleted.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is related to a question at http://stackoverflow.com/questions/26165041/variable-in-a-closure-to-avoid-multiple-ifs/26165265?noredirect=1#comment41022839_26165265