grails criteria eq not working

266 Views Asked by At

I have problem with criteria in grails

I have a domain User and another domain Conversation Conversation has Many Participants(domain)

When I do like this:

def c = Conversation.createCriteria();
        c.get{
            createAlias('participants', 'p')
            eq 'p.user', user
            eq 'p.folder', folder
            eq 'p.unread', true
            projections{
                count('id')
            }
        }

It gives wrong output by showing the following criteria failure :

abc.Conversation : 1
    eq('[XYZ]', 'XYZ') == false

    sorry
conv == []

Can anybody help?

1

There are 1 best solutions below

2
On

the standard way to look through hasMany in criteria is this:

def c = Conversation.withCriteria{
          participants{
            eq 'user', user
            eq 'folder', folder
            eq 'unread', true
          }
          ....
 }