Commit 1b00d7f20c6f79c363d1bd573e348e0381e606f5

Authored by Ábner Silva de Oliveira
2 parents b27c4c3a 48c67502

merge with upstream

Showing 1 changed file with 10 additions and 32 deletions   Show diff stats
app/models/choice.rb
@@ -70,12 +70,11 @@ class Choice < ActiveRecord::Base @@ -70,12 +70,11 @@ class Choice < ActiveRecord::Base
70 70
71 def compute_score! 71 def compute_score!
72 self.score = compute_score 72 self.score = compute_score
73 - #changed to quote tables according the database type (wasn't working in postgres)  
74 - Choice.connection.execute("UPDATE #{connection.quote_table_name("choices")}  
75 - SET #{connection.quote_column_name("score")} = #{self.score},  
76 - #{connection.quote_column_name("updated_at")} = '#{Time.now.utc.to_s(:db)}'  
77 - WHERE  
78 - #{connection.quote_column_name("id")} = #{self.id}") 73 + conn = Choice.connection
  74 + conn.execute("UPDATE #{conn.quote_table_name('choices')} SET
  75 + #{conn.quote_column_name('score')} = #{self.score},
  76 + #{conn.quote_column_name('updated_at')} = '#{Time.now.utc.to_s(:db)}' WHERE
  77 + #{conn.quote_column_name('id')} = #{self.id}")
79 end 78 end
80 79
81 def user_created 80 def user_created
@@ -126,37 +125,16 @@ class Choice < ActiveRecord::Base @@ -126,37 +125,16 @@ class Choice < ActiveRecord::Base
126 125
127 #add prompts with this choice on the left 126 #add prompts with this choice on the left
128 previous_choices.each do |r| 127 previous_choices.each do |r|
129 - inserts.push("(NULL, #{self.question_id}, NULL, #{self.id}, '#{timestring}', '#{timestring}', NULL, 0, #{r.id}, NULL, NULL)") 128 + inserts.push("(NULL, #{self.question_id}, NULL, #{self.id}, '#{timestring}', '#{timestring}', NULL, 0, #{r.id}, NULL, NULL)")
130 end 129 end
131 #add prompts with this choice on the right 130 #add prompts with this choice on the right
132 previous_choices.each do |l| 131 previous_choices.each do |l|
133 - inserts.push("(NULL, #{self.question_id}, NULL, #{l.id}, '#{timestring}', '#{timestring}', NULL, 0, #{self.id}, NULL, NULL)") 132 + inserts.push("(NULL, #{self.question_id}, NULL, #{l.id}, '#{timestring}', '#{timestring}', NULL, 0, #{self.id}, NULL, NULL)")
134 end 133 end
135 - #changed to quote tables according the database type (wasn't working in postgres)  
136 - sql = "INSERT INTO #{connection.quote_table_name("prompts")}  
137 - (#{connection.quote_column_name("algorithm_id")},  
138 - #{connection.quote_column_name("question_id")},  
139 - #{connection.quote_column_name("voter_id")},  
140 - #{connection.quote_column_name("left_choice_id")},  
141 - #{connection.quote_column_name("created_at")},  
142 - #{connection.quote_column_name("updated_at")},  
143 - #{connection.quote_column_name("tracking")},  
144 - #{connection.quote_column_name("votes_count")},  
145 - #{connection.quote_column_name("right_choice_id")},  
146 - #{connection.quote_column_name("active")},  
147 - #{connection.quote_column_name("randomkey")}) VALUES #{inserts.join(', ')}"  
148 - 134 + conn = Prompts.connection
  135 + sql = "INSERT INTO #{conn.quote_table_name('prompts')} (#{conn.quote_column_name('algorithm_id')}, #{conn.quote_column_name('question_id')}, #{conn.quote_column_name('voter_id')}, #{conn.quote_column_name('left_choice_id')}, #{conn.quote_column_name('created_at')}, #{conn.quote_column_name('updated_at')}, #{conn.quote_column_name('tracking')}, #{conn.quote_column_name('votes_count')}, #{conn.quote_column_name('right_choice_id')}, #{conn.quote_column_name('active')}, #{conn.quote_column_name('randomkey')}) VALUES #{inserts.join(', ')}"
149 Question.update_counters(self.question_id, :prompts_count => 2*previous_choices.size) 136 Question.update_counters(self.question_id, :prompts_count => 2*previous_choices.size)
150 -  
151 -  
152 - ActiveRecord::Base.connection.execute(sql)  
153 -  
154 -#VALUES (NULL, 108, NULL, 1892, '2010-03-16 11:12:37', '2010-03-16 11:12:37', NULL, 0, 1893, NULL, NULL)  
155 -# INSERT INTO `prompts` (`algorithm_id`, `question_id`, `voter_id`, `left_choice_id`, `created_at`, `updated_at`, `tracking`, `votes_count`, `right_choice_id`, `active`, `randomkey`) VALUES(NULL, 108, NULL, 1892, '2010-03-16 11:12:37', '2010-03-16 11:12:37', NULL, 0, 1893, NULL, NULL)  
156 - #previous_choices.each { |c|  
157 - # question.prompts.create!(:left_choice => c, :right_choice => self)  
158 - # question.prompts.create!(:left_choice => self, :right_choice => c)  
159 - #} 137 + conn.execute(sql)
160 end 138 end
161 end 139 end
162 140