has_many :through and named_scope

   I have the models roles, users and user_roles. The relationship among
them is


user1.roles returns an array of roles.
The array class has a function "include?(obj)" that returns true or

Something like this should work:

Named scopes are not ment for stuff like this.
You can create a function on the user model "is_admin?" for the code
above. That way if how an admin is defined changes, you only need to
update the code in one place.

Better off saying !roles.find_by_name("admin").blank?
Saves on SQL

Blog: http://random8.zenunit.com/
Twitter: http://twitter.com/random8r
Learn: http://sensei.zenunit.com/
New video up now at http://sensei.zenunit.com/ real fastcgi rails deploy process! Check it out now!