I need a groovy criteria to get all the elements after i make sort on nullable inner object

Posted by user1773876 on Stack Overflow See other posts from Stack Overflow or by user1773876
Published on 2012-10-25T10:48:06Z Indexed on 2012/10/25 11:00 UTC
Read the original article Hit count: 291

Filed under:

I have two domain classes named IpPatient,Ward as shown below.

class IpPatient {
  String ipRegNo
  Ward ward

  static constraints = {
    ward nullable:true
    ipRegNo nullable:false
  }
}

class Ward
{
  String name;

  static constraints = {
    name nullable:true
  }
}

now i would like to create criteria like

def criteria=IpPatient.createCriteria()
return criteria.list(max:max , offset:offset) {
  order("ward.name","asc")  
  createAlias('ward', 'ward', CriteriaSpecification.LEFT_JOIN)
}

At present IpPatient table has 13 records, where 8 records of IpPatient doesn't have ward because ward can be null.

when i sort with wardName i am getting 5 records those contain ward.

I need a criteria to get all the elements after i make sort on nullable inner object.

© Stack Overflow or respective owner

Related posts about grails