Jacob
Jacob

Reputation: 4031

Correct use of AND,OR operator with grails criteria

I am trying to build a criteria using grails createCriteria.criteria like this

Controller.createCriteria().listDistinct(){
and {
   or{
          or{
             //condition1
             //condition2
            }
          or{
             //condition3
             //condition4
            }

     }

//condition 5
}

}

but what I get is this:

 where
        (
            (
                (
                    condition 1
                    or condition2
                ) 
                or (
                    condition 3 
                    or condition 4
                )
            )
        ) 

How should I correctly position the clauses?

Upvotes: 0

Views: 1053

Answers (1)

Solci
Solci

Reputation: 416

Have you tried using only one OR to simplify things. I'm thinking in something like:

and {
    or{
        //condition1
        //condition2
        //condition3
        //condition4
    }
    //condition 5
}

It will generate less complicated SQL

Upvotes: 6

Related Questions