From 5feb02c31d02de5e3d45ea261e8d415a7c97020b Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Wed, 8 Jan 2014 14:53:29 +0000 Subject: [PATCH] Rails4: replace deprecated Relation#calculate with finder options at Issue model git-svn-id: http://svn.redmine.org/redmine/trunk@12537 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/issue.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 295cedbc8..abf4cec92 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -1338,7 +1338,7 @@ class Issue < ActiveRecord::Base def recalculate_attributes_for(issue_id) if issue_id && p = Issue.find_by_id(issue_id) # priority = highest priority of children - if priority_position = p.children.maximum("#{IssuePriority.table_name}.position", :joins => :priority) + if priority_position = p.children.joins(:priority).maximum("#{IssuePriority.table_name}.position") p.priority = IssuePriority.find_by_position(priority_position) end @@ -1357,8 +1357,9 @@ class Issue < ActiveRecord::Base if average == 0 average = 1 end - done = p.leaves.sum("COALESCE(CASE WHEN estimated_hours > 0 THEN estimated_hours ELSE NULL END, #{average}) " + - "* (CASE WHEN is_closed = #{connection.quoted_true} THEN 100 ELSE COALESCE(done_ratio, 0) END)", :joins => :status).to_f + done = p.leaves.joins(:status). + sum("COALESCE(CASE WHEN estimated_hours > 0 THEN estimated_hours ELSE NULL END, #{average}) " + + "* (CASE WHEN is_closed = #{connection.quoted_true} THEN 100 ELSE COALESCE(done_ratio, 0) END)").to_f progress = done / (average * leaves_count) p.done_ratio = progress.round end