Skip to content

Commit 53f4b87

Browse files
committed
Fix bug on deleting while using mysql 5.7
Move `DISTINCT` keyword to inner query to force the derived table to be materialized in the query deleting hierarchy references. Issue: ClosureTree#190 Same issue in Rails: rails/rails#19281 Related MySQL reference: http://dev.mysql.com/doc/refman/5.7/en/upgrading-from-previous-series.html
1 parent 6a67e3a commit 53f4b87

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/closure_tree/hierarchy_maintenance.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ def delete_hierarchy_references
9494
_ct.connection.execute <<-SQL.strip_heredoc
9595
DELETE FROM #{_ct.quoted_hierarchy_table_name}
9696
WHERE descendant_id IN (
97-
SELECT DISTINCT descendant_id
98-
FROM (SELECT descendant_id
97+
SELECT descendant_id
98+
FROM (SELECT DISTINCT descendant_id
9999
FROM #{_ct.quoted_hierarchy_table_name}
100100
WHERE ancestor_id = #{_ct.quote(id)}
101101
OR descendant_id = #{_ct.quote(id)}

0 commit comments

Comments
 (0)