summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2017-04-04 18:00:20 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2017-04-04 18:00:20 +0000
commitfbde611f3f4eb681cffaaab76ab8761d0053a85e (patch)
treec45f5fdfd3149e0cc4afcaae26be458e63be30bc /app
parent70b0bc5168aff813398334d859db1212e86a2b48 (diff)
downloadredmine-fbde611f3f4eb681cffaaab76ab8761d0053a85e.tar.gz
redmine-fbde611f3f4eb681cffaaab76ab8761d0053a85e.zip
Use #to_sql to generate the subquery.
git-svn-id: http://svn.redmine.org/redmine/trunk@16482 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/models/issue_status.rb13
1 files changed, 7 insertions, 6 deletions
diff --git a/app/models/issue_status.rb b/app/models/issue_status.rb
index bdf096121..1a1beaf1c 100644
--- a/app/models/issue_status.rb
+++ b/app/models/issue_status.rb
@@ -92,12 +92,13 @@ class IssueStatus < ActiveRecord::Base
if is_closed_changed? && is_closed == true
# First we update issues that have a journal for when the current status was set,
# a subselect is used to update all issues with a single query
- subselect = "SELECT MAX(j.created_on) FROM #{Journal.table_name} j" +
- " JOIN #{JournalDetail.table_name} d ON d.journal_id = j.id" +
- " WHERE j.journalized_type = 'Issue' AND j.journalized_id = #{Issue.table_name}.id" +
- " AND d.property = 'attr' AND d.prop_key = 'status_id' AND d.value = :status_id"
- Issue.where(:status_id => id, :closed_on => nil).
- update_all(["closed_on = (#{subselect})", {:status_id => id.to_s}])
+ subquery = Journal.joins(:details).
+ where(:journalized_type => 'Issue').
+ where("journalized_id = #{Issue.table_name}.id").
+ where(:journal_details => {:property => 'attr', :prop_key => 'status_id', :value => id.to_s}).
+ select("MAX(created_on)").
+ to_sql
+ Issue.where(:status_id => id, :closed_on => nil).update_all("closed_on = (#{subquery})")
# Then we update issues that don't have a journal which means the
# current status was set on creation