gunboxer gunboxer - 5 months ago 39
Groovy Question

Groovy domain class find with only provided filter


I need to perform Domain class filtering in Groovy for provided filter fields.
Here is code sample:

User.findAll(name:, age: filter.age, department: filter.department)

Is there exists some syntax sugar to help me to validate if for example is not provided e.g. null or empty - do not filter by this field. Thanks.


Abs has right. Here is an example with if-statements for not provided filter fields:

User.createCriteria().list {
  if (       eq("name",
  if (filter.age)        eq("age", filter.age)
  if (filter.department) eq("department", filter.department)