Skip to content

Instantly share code, notes, and snippets.

@jhubert
Created June 6, 2009 08:52
Show Gist options
  • Save jhubert/124779 to your computer and use it in GitHub Desktop.
Save jhubert/124779 to your computer and use it in GitHub Desktop.
class User
has_many :methods
has_many :options, :through => :methods
def points
connection.execute("SELECT SUM(points) as points FROM options o INNER JOIN methods m ON m.option_id = o.id WHERE m.user_id = '#{user_id}'").first['points']
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment