From a78c7249029828685173ecd86151fb80546d3032 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Thu, 18 Aug 2016 14:58:25 +0000 Subject: [PATCH] MySQL: You can't specify target table for update in FROM clause (#23347). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch by Felix Schäfer. git-svn-id: http://svn.redmine.org/redmine/trunk@15737 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- .../20150525103953_clear_estimated_hours_on_parent_issues.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20150525103953_clear_estimated_hours_on_parent_issues.rb b/db/migrate/20150525103953_clear_estimated_hours_on_parent_issues.rb index 8eed815f7..c00ada096 100644 --- a/db/migrate/20150525103953_clear_estimated_hours_on_parent_issues.rb +++ b/db/migrate/20150525103953_clear_estimated_hours_on_parent_issues.rb @@ -6,7 +6,7 @@ class ClearEstimatedHoursOnParentIssues < ActiveRecord::Migration def self.down table_name = Issue.table_name - leaves_sum_select = "SELECT SUM(leaves.estimated_hours) FROM #{table_name} leaves" + + leaves_sum_select = "SELECT SUM(leaves.estimated_hours) FROM (SELECT * FROM #{table_name}) AS leaves" + " WHERE leaves.root_id = #{table_name}.root_id AND leaves.lft > #{table_name}.lft AND leaves.rgt < #{table_name}.rgt" + " AND leaves.rgt = leaves.lft + 1"