开发者

GORM: ilke and inList combination

开发者 https://www.devze.com 2023-03-31 17:48 出处:网络
In Grai开发者_StackOverflowls, with DynamicFinder how can we execute a query using ilike along with inList? Or can we use CriteriaBuilder to combine ilike and inList? Thank you!why do you want do comb

In Grai开发者_StackOverflowls, with DynamicFinder how can we execute a query using ilike along with inList? Or can we use CriteriaBuilder to combine ilike and inList? Thank you!


why do you want do combine ilike and inList? InList is a constraint and defined as follows http://www.grails.org/doc/latest/ref/Constraints/inList.html. So your attribte with this constraint can only hold data defined in this list. e.g.

name(inList:["Frey", "Fred", "Flip"] )

Test.createCriteria.list {
    like("name","F%")
}


Build query on the fly:

def filter = ['a', 'bb', 'c']

def res = DomainClass.withCriteria {
  or {
    filter.each { 
      ilike('property', "%$it%")
    }
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消