views:

29

answers:

1
named_scope :all_public, lambda { |users| 
       { :conditions =>  ["visibility = ? || (visibility = ? && user_id = ?)", Shared::PUBLIC, Shared::PRIVATE, users] }
     }

that works nice for one user, but is there a way to modify it to work where users is an array of user ids?

A: 

Something like this and then just pass a single element array for the single ID case

named_scope :all_public, lambda { |users| 
       { :conditions =>  ["visibility = ? OR (visibility = ? AND user_id IN (?))", Shared::PUBLIC, Shared::PRIVATE, users.join(',')] }
     }
bjg
mark
@mark Yes you'd be correct if the argument was an array of `User` objects but I understood from the question that it would be an array of IDs. Either way, I agree, the caller must do the `collect` either before or inside the named scope
bjg
You're right, if it were to have worked for a single user then it would also have needed an id. Naming convention is to blame. :)
mark
shhh. naming some stuff is hard. (not here, but like named scope with two parameters where the visibility can change and so can the user_ids object) =p
DerNalia
actually this isn't what I want. =( posting more specific question soon.
DerNalia