0

I have a grails Domain called Connection. This domain contains a User instant in it called myFriend. I want to write a Query that returns all the connections where myFriend.firstName is Dave for example. Since this object is embedded within Connection, I don't know how to query that. Any suggestion ? I tried to use FindAllBy and Where queries but no luck.

Findings: I figured out a two step process to make this work, but I wish to make it a one process if possible. First I get the list of all "myFriend's id" from the Connection table, then I use that to query the User table and filter on the firstName. then use the inList to get all those users from the Connection table that their name starts with some letter.

AlexCon
  • 1,127
  • 1
  • 13
  • 31

1 Answers1

0

I finally found out a solution based on this post: How to create criteria in groovy/grails for nested object?

In my Service

def criteria = Connection.createCriteria(); 
def results = criteria.list { 
                myConnection {                          
                    like("firstName", "${queryText}%")                          
                    } 
                }; 
return results;

My Domains

class User {
    String firstName
}

class Connection {
    User myConnection
}
Community
  • 1
  • 1
AlexCon
  • 1,127
  • 1
  • 13
  • 31