Skip to content

Commit

Permalink
changed lines to allow postres to work as per bouchard#36 on thumbs_u…
Browse files Browse the repository at this point in the history
…p master
  • Loading branch information
rustyb committed Apr 1, 2012
1 parent a0cd47b commit bc21143
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/acts_as_voteable.rb
Expand Up @@ -25,9 +25,11 @@ module SingletonMethods
def plusminus_tally(params = {})
t = self.joins("LEFT OUTER JOIN #{Vote.table_name} ON #{self.table_name}.id = #{Vote.table_name}.voteable_id")
t = t.order("plusminus_tally DESC")
t = t.group("#{self.table_name}.id")
#t = t.group("#{self.table_name}.id")
t = t.group("#{self.column_names_for_tally}")
t = t.select("#{self.table_name}.*")
t = t.select("SUM(CASE CAST(#{Vote.table_name}.vote AS UNSIGNED) WHEN 1 THEN 1 WHEN 0 THEN -1 ELSE 0 END) AS plusminus_tally")
#t = t.select("SUM(CASE CAST(#{Vote.table_name}.vote AS UNSIGNED) WHEN 1 THEN 1 WHEN 0 THEN -1 ELSE 0 END) AS plusminus_tally")
t = t.select("SUM(CASE CAST(#{Vote.table_name}.vote AS #{ActiveRecord::Base.connection.type_to_sql(:integer)}) WHEN 1 THEN 1 WHEN 0 THEN -1 ELSE 0 END) AS plusminus")
if params[:separate_updown]
t = t.select("SUM(CASE CAST(#{Vote.table_name}.vote AS UNSIGNED) WHEN 1 THEN 1 WHEN 0 THEN 0 ELSE 0 END) AS up")
t = t.select("SUM(CASE CAST(#{Vote.table_name}.vote AS UNSIGNED) WHEN 1 THEN 0 WHEN 0 THEN 1 ELSE 0 END) AS down")
Expand Down

0 comments on commit bc21143

Please sign in to comment.