Suppose, I have two class named User and Authority.
The specification of those two classes are:
User{
Integer id;
String userCode;
String password;
boolean active;
static hasMany = [authorities : Authority, userGroups : UserGroup]
static mapping = {
table("security_user")
}
}
Authority{
Integer id
String roleTitle
String description
static hasMany = [features : Feature, users : User]
static belongsTo = User;
}
In the Query level how can I get all the authorities those are mapped with one particular object of User?
Like, I have tried in the following approach:
user = User.findByUserCodeAndPassword(userCode,password);
Set<User> users = new HashSet<User>();
users.add(user);
List<Authority> authority = Authority.findAllByUsers(users);
But the above code is giving runtime grails exception. How can I solve this issue?
Just use
user.authoritiesno need to do all these things after getting user object.