Project

General

Profile

Actions

Defect #21581

closed

Statement invalid error on including default scope by patching a model.

Added by Rupesh J about 9 years ago. Updated almost 9 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Affected version:

Description

In plugin development, It is not possible to add the default scope by patching any models.

def self.included(base) # :nodoc:
        base.extend(ClassMethods)
        base.send(:include, InstanceMethods)

        base.class_eval do
           default_scope -> { includes(:table_name) }
....

The tests fail with Statement Invalid.

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)

I guess, the following is the culprit, issue_nested_set.rb

      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)

Can you please look into this issue.

Happens in Redmine 3.0.3
Ruby 2.1

Actions #1

Updated by Toshi MARUYAMA almost 9 years ago

  • Description updated (diff)
Actions #2

Updated by Toshi MARUYAMA almost 9 years ago

  • Description updated (diff)
Actions #4

Updated by Toshi MARUYAMA almost 9 years ago

  • Status changed from New to Needs feedback
Actions #5

Updated by Rupesh J almost 9 years ago

Thank You very much.
Issue resolved.

Actions #6

Updated by Toshi MARUYAMA almost 9 years ago

  • Status changed from Needs feedback to Closed

Thank you for your feedback.

Actions

Also available in: Atom PDF