Defect #21581
Updated by Toshi MARUYAMA almost 9 years ago
In plugin development, It is not possible to add the default scope by patching any models. <pre><code class="ruby"> <pre> def self.included(base) # :nodoc: base.extend(ClassMethods) base.send(:include, InstanceMethods) base.class_eval do default_scope -> { includes(:table_name) } .... </code></pre> </pre> The tests fail with Statement Invalid. <pre> IssueNestedSetTest#test_move_a_root_to_child: ActiveRecord::StatementInvalid: Mysql2::Error: Column 'id' in where clause is ambiguous: SELECT MAX(`issues`.`rgt`) FROM `issues` LEFT OUTER JOIN `egs` ON `egs`.`issue_id` = `issues`.`id` WHERE `issues`.`root_id` = 1372 AND `issues`.`parent_id` = 1372 AND (id < 1373) </pre> I guess, the following is the culprit, issue_nested_set.rb <pre><code class="ruby"> <pre> def target_lft scope_for_max_rgt = self.class.where(:root_id => root_id).where(:parent_id => parent_id) if id scope_for_max_rgt = scope_for_max_rgt.where("id < ?", id) </code></pre> </pre> Can you please look into this issue. Happens in Redmine 3.0.3 Ruby 2.1