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
This commit is contained in:
Toshi MARUYAMA 2014-01-08 14:53:29 +00:00
parent 66bdc014d4
commit 5feb02c31d
1 changed files with 4 additions and 3 deletions

View File

@ -1338,7 +1338,7 @@ class Issue < ActiveRecord::Base
def recalculate_attributes_for(issue_id) def recalculate_attributes_for(issue_id)
if issue_id && p = Issue.find_by_id(issue_id) if issue_id && p = Issue.find_by_id(issue_id)
# priority = highest priority of children # 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) p.priority = IssuePriority.find_by_position(priority_position)
end end
@ -1357,8 +1357,9 @@ class Issue < ActiveRecord::Base
if average == 0 if average == 0
average = 1 average = 1
end end
done = p.leaves.sum("COALESCE(CASE WHEN estimated_hours > 0 THEN estimated_hours ELSE NULL END, #{average}) " + done = p.leaves.joins(:status).
"* (CASE WHEN is_closed = #{connection.quoted_true} THEN 100 ELSE COALESCE(done_ratio, 0) END)", :joins => :status).to_f 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) progress = done / (average * leaves_count)
p.done_ratio = progress.round p.done_ratio = progress.round
end end