grails-data-mapping icon indicating copy to clipboard operation
grails-data-mapping copied to clipboard

Support empty list argument in dynamic finder inList

Open demon101 opened this issue 6 years ago • 3 comments

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

demon101 avatar Jan 03 '19 10:01 demon101

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

jeffscottbrown avatar Jan 19 '19 22:01 jeffscottbrown

@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.

demon101 avatar Jan 19 '19 22:01 demon101

@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?

demon101 avatar Jan 20 '19 16:01 demon101