Pass List of Enumerated Criteria

I have a domain Payment

class Payment {
  String name
  PaymentType paymentType
}

PaymentType - ENUM

finding all payments of a particular type of payment is simple

def results = Payment.createCriteria.list = {
  'in' ('paymentType', PaymentType.valueOf(params.paymentType))
}

how can I deal with a situation where I want to search for all payments against more than one type of payment, i.e. if params.paymentType is an array?

+3
source share
2 answers

If PaymentType is an array, you can do something like this:

def results = Payment.createCriteria().list {
   'in' ('paymentType', params.paymentType.collect{PaymentType.valueOf(it)})
}
+6
source

@ataylor:

I'm not sure, but should not

def results = Payment.createCriteria().list { 'in' ('paymentType',new params.paymentType.collect{PaymentType.valueOf(it)}) }

or you get an error message

groovy.lang.MissingPropertyException: No such property: params for class: grails.orm.HibernateCriteriaBuilder

0
source

Source: https://habr.com/ru/post/1776384/


All Articles