Hello,
Lets say I have two domain classes:
class User {
String name
Role role
}
class Role {
String name
static belongsTo = [user: User]
}
and I create some records:
def r1 = new Role(name: "role1").save()
def r2 = new Role(name: "role2").save()
new User(name: "user1", role: r1).save()
new User(name: "user2", role: r2).save()
new User(name: "user3", role: r1).save()
How can I now select my users by role? I would expect to be able to do one of the following:
def role = Role.findByName("role1"); //returns a Role with [ id:1 name:"role1" ]
User.findAllByRole(role) //returns null
User.findAllByRole(new Role(name: "role1")) //returns null
User.findAllByRole(role.id) //returns null
User.findAllByRole(id: role.id) //returns null
Is it possible for a domain class to find other associated domain classes using the dynamic find* methods? I can do it using namedQueries, but id rather not because I dont want to have to write them out for every relationship I have between domain classes