Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing Enum List to Criteria

I have a domain Payment

class Payment {
  String name
  PaymentType paymentType
}

PaymentType is an ENUM

to search all payments of a particular payment type is simple

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

how can i handle the situation when I want to search all Payments against more then one payment type i.e. if params.paymentType is an array?

like image 755
Hussain Fakhruddin Avatar asked Nov 29 '25 17:11

Hussain Fakhruddin


1 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)})
}
like image 93
ataylor Avatar answered Dec 02 '25 09:12

ataylor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!