Hi
I have the tables
users, roles, memberships( join table between users and roles. Between
users and roles there is has_many :through relation ship)
privileges, permissions (join table between roles and privileges.
Between roles and privileges there is has_many :through relation ship)
privileges table entries like
1 add_user
2 delete_user ,…
roles tables entries like
1 admin
2 participant,…
Now to find whether a given user(with id=2) has a privilege like
‘add_user’ I wrote a query like
select memberships.id from memberships inner join permissions on
memberships.role_id=permissions.role_id where memberships.user_id=2 and
permissions.privilege_id=(select id from privileges where privilege_name
=‘add_user’);
And I get the correct result. Now I would like to know how I can
write the above query in an activerecord style.Please help
Thanks in advance
Tom