Hello there, I am building an application where users are distributed among different user groups (User has_many UserGroup). But there is a specific type of User (admin) that I would like to belong to ALL groups. I know I can add them to the group on the after_create or after_update method of UserGroup, but I would like to do something different. My question is: Is it possible that user.user_groups return all groups if the user is an admin, and the normal group list if he is not? Admin is a boolean field of User. if you need more info, please let me know. best, Dante --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
finder_sql may be a way to do this, something like: has_many :user_groups, :finder_sql => "SELECT DISTINCT user_groups.* FROM user_groups #{''WHERE user_groups.user_id = '' + id unless admin}" -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 30 May 2008, at 14:10, Thorsten Mueller wrote:> > finder_sql may be a way to do this, something like: > > has_many :user_groups, :finder_sql => "SELECT DISTINCT user_groups.* > FROM user_groups #{''WHERE user_groups.user_id = '' + id unless admin}"although that will have to be => ''...'' so that this is interpolated at the right point in time Fred> > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---