Grails createCriteria syntax error

71 Views Asked by At

I am trying to create a list of companies which appear in either of 2 other lists. I can manage to create a list of companies appearing in 1 other list like this :-

       List masterList = Companies.createCriteria().list(){
            'in'("companyname", alistofcompanies) 
            and {
                or{
                    eq("type","T1")
                    eq("type","T2")
                }                
             order ("companyname")
            }     
        }

But I don't know how to look for companies in either of 2 other lists. I tried this :-

    List masterList = Companies.createCriteria().list(){
            or{
               'in'("companyname", alistofcompanies) 
               'in'("companyname", anotherlistofcompanies)
             }
            and {
                or{
                    eq("type","T1")
                    eq("type","T2")
                }                
             order ("companyname")
            }     
      }

but it gives me a syntax error.

Any clues how I should structure this?

1

There are 1 best solutions below

2
Shivam Pandey On

I don't see any syntax issue except you can improve the code and it is working.

 List masterList = Companies.createCriteria().list() {
            'in'("companyname", alistofcompanies + anotherlistofcompanies)
            'in'("type", ["T1", "T2"])
             order("companyname")
  }