Reputation: 49451
I have a domain class linked as such:
class Item{
static hasMany = [children:Item]
Item parent
}
We are dealing with existing data (not created by grails). One important detail is that if an Item has no parent, the column "parentid" shows "0", not null. To deal with this I had to add:
columns{
parent column: 'parentid', ignoreNotFound: true
}
So far so good. Now the problem arises when I want to write a Criteria search for items WITH NO PARENTS. That is, items with parentid=0.
I tried eq('parent', 0)
but it crashed (casting exceptions, mismatch, etc ...), because I assume it expects an object.
I tried eq('parent', null)
but it returned no results, because I there are no NULL items.
What's the best way to handle that?
Upvotes: 0
Views: 676