connor moore
connor moore

Reputation: 611

Grails withCriteria And/Or cases?

I have the following Grails withCriteria structure:

allInfo = Scholarship.withCriteria {
    between('gpa', '0', gpa)
    grades {
      idEq year
    }
    scholarshipCounties {
        eq('county.id', county)
    }
    majors {
      idEq major
    }
    activities {
        idEq activity
    }
    eq('specialTypeInd', special)
}

I want this to return scholarships by (gpa AND grades AND majors) OR scholarshipCounties OR activities OR specialTypeInd.

Upvotes: 0

Views: 248

Answers (1)

injecteer
injecteer

Reputation: 20699

you should be using respective or{} and and{} clauses:

allInfo = Scholarship.withCriteria {
  and{
    between('gpa', '0', gpa)
    grades {
      idEq year
    }
    majors {
      idEq major
    }
  }
  or{
    scholarshipCounties {
        eq('county.id', county)
    }

    activities {
        idEq activity
    }
    eq('specialTypeInd', special)
  }
}

Upvotes: 1

Related Questions