Reputation: 65173
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?
Upvotes: 1
Views: 2460
Reputation: 7477
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(',')] }
}
Upvotes: 1