Skip to content

Instantly share code, notes, and snippets.

@dekart
Created March 23, 2009 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dekart/83497 to your computer and use it in GitHub Desktop.
Save dekart/83497 to your computer and use it in GitHub Desktop.
named_scope :victims_for, Proc.new{|attacker|
{
:conditions => [
%{
(level BETWEEN :low_level AND :high_level) AND
characters.id NOT IN (
SELECT fights.victim_id FROM fights WHERE attacker_id = :attacker_id AND winner_id = :attacker_id AND fights.created_at > :time_limit
) AND
characters.id != :attacker_id
},
{
:low_level => attacker.level,
:high_level => attacker.level + 2,
:attacker_id => attacker.id,
:time_limit => 1.hour.ago
}
],
:include => :user
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment