I have a Rails Application that is having User ,Role , Group models.
User Model
has_and_belongs_to_many :roles
has_and_belongs_to_many :groups
Role Model
has_and_belongs_to_many :users
Group Model
has_and_belongs_to_many :users
I have also created a mapping tables like,
roles_users and groups_users for mapping their id
So here each user can have multiple groups ans roles ,
in my role model there is only three entries,
admin with id 1,
trainer with id 2,
trainee with id 3
i want to find all users under a particular group with role id = 3,
i have done like this,
@group = Group.find(2)
@users = @group.users
here i am getting all users under group id =2 ,but i want to filter it again with role id = 3. How to fix this.
Any help is appreciated.
Try: