grails-data-mapping
grails-data-mapping copied to clipboard
Support empty list argument in dynamic finder inList
Now with posgresql BD Book.findAllByYearInList([]) fails with wrong sql exception "in ()" At result, dummy code with isEmpty() checking have to be written additionally to business code
Will try to provide PR
https://github.com/grails/grails-data-mapping/blob/master/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/finders/MethodExpression.java#L250
Environment Information
- Operating System: TODO
- GORM Version: TODO
- Grails Version (if using Grails): 3.2.11
- JDK Version: TODO
Example Application
- TODO: link to github repository with example that reproduces the issue
Some related issues:
https://github.com/grails/grails-data-mapping/issues/1160
https://github.com/grails/grails-core/issues/9352
https://github.com/grails/grails-core/issues/630
https://github.com/grails/grails-core/issues/7801
@jeffbrown good list. I'm not alone with this problem =) This finder has to return an empty result without any DB query if argument null (thx https://github.com/grails/grails-core/issues/7801) or empty.
The only problem, how to code it. But Dynamic finders code really good and interesting. I hope, I will find time for codding.
@jeffbrown @graemerocher
Since MethodExpression has no mechanism for stopping evaluation, I see the only hacky way with using negative logical expression generation. Something like:
property is null and property is not null
. (I can't find how to construct true=false expression with Restrictions class)
def a = Restrictions.isNull(property)
def b = Restrictions.isNotNull(property)
Restrictions.and(a, b)
As I know, result query will be simply optimized by DB without performance penalty
The same logic can be used for InRange expression too.
Is it ok? Or you can toss me any ideas?