Hi to everyone,
I have my User model which has_many roles. Now, I've the need to find all users with certain roles.
At first I thought of something like
User.find(:all, :joins => :roles).select { |u| u.has_role?(:admin) }
But this seems unnatural to me, because it forces to load all the Users and then applying a filter on the collections.
Is there a way to obtain the same result in a better way?
Perhaps something like:
User.find(:all, :joins => :roles, :conditions => [ "'admin' in roles" ])
Thanks in advance for your help.
Regards, Carmine