0

I have a domain class Person, as below

class Person {
   static hasMany=[cars:Car]
}

Now, i want fetch all Person, who doesn't own a 'Ford' car. The problem with below criteria is that, it fetches 'Person' with two cars, out of which one is 'Ford'.

List promotions = Person.createCriteria().list(  ) {
    cars {
        ne(‘name’, ‘Ford’)
    }
}
Ashish Joseph
  • 1,103
  • 3
  • 12
  • 35
  • possible duplicate of [Is there a 'does not contains' functionality on a collection property of a domain object for createCriteria?](http://stackoverflow.com/questions/24180418/is-there-a-does-not-contains-functionality-on-a-collection-property-of-a-domai) – MKB Jan 22 '15 at 10:13
  • Is there a criteria based solution? – Ashish Joseph Jan 22 '15 at 13:26

1 Answers1

1
List promotions = Person.createCriteria().list(  ) {       
 sqlRestriction " id not in (select person_id from car where 'Ford' = name );"
}
dsharew
  • 10,377
  • 6
  • 49
  • 75