Skip to content

Instantly share code, notes, and snippets.

@srbiv
Created November 30, 2012 19:40
Show Gist options
  • Save srbiv/4178035 to your computer and use it in GitHub Desktop.
Save srbiv/4178035 to your computer and use it in GitHub Desktop.
@messages = Message.search do
any_of do
with(:user_ids, current_user.id)
all_of do
with(:user_ids).blank?
with(:school_ids, current_user.affiliated_school_ids.map {|s| s.to_s })
end
all_of do
with(:user_ids).blank?
with(:school_ids).blank?
with(:customer_ids, current_user.affiliated_customer_ids.map { |c| c.to_s })
end
unless current_user.affiliated_customer.contests.empty?
all_of do
with(:user_ids).blank?
with(:school_ids).blank?
with(:customer_ids).blank?
with(:contest_ids, current_user.affiliated_customer.contests.map { |c| c.id.to_s })
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment