From 59feaeb186970627bad306b3952e012101ab39d6 Mon Sep 17 00:00:00 2001 From: Ken Collins Date: Wed, 6 May 2009 08:58:59 -0400 Subject: [PATCH] [Rails2.3] Change #attribute_condition to work which now has multiple args in 2.3. --- lib/grouped_scope.rb | 1 + lib/grouped_scope/core_ext.rb | 18 +++++++++++++----- lib/grouped_scope/has_many_association.rb | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/grouped_scope.rb b/lib/grouped_scope.rb index 80b263c..ec30270 100644 --- a/lib/grouped_scope.rb +++ b/lib/grouped_scope.rb @@ -1,3 +1,4 @@ +require 'active_record/version' require 'grouped_scope/errors' require 'grouped_scope/grouping' require 'grouped_scope/self_grouping' diff --git a/lib/grouped_scope/core_ext.rb b/lib/grouped_scope/core_ext.rb index 061a7fe..ed6754a 100644 --- a/lib/grouped_scope/core_ext.rb +++ b/lib/grouped_scope/core_ext.rb @@ -5,13 +5,21 @@ class << self private - def attribute_condition_with_grouped_scope(argument) - case argument - when GroupedScope::SelfGroupping then "IN (?)" - else attribute_condition_without_grouped_scope(argument) + def attribute_condition_with_grouped_scope(*args) + if ActiveRecord::VERSION::STRING >= '2.3.0' + quoted_column_name, argument = args + case argument + when GroupedScope::SelfGroupping then "#{quoted_column_name} IN (?)" + else attribute_condition_without_grouped_scope(quoted_column_name,argument) + end + else + argument = args.first + case argument + when GroupedScope::SelfGroupping then "IN (?)" + else attribute_condition_without_grouped_scope(argument) + end end end - alias_method_chain :attribute_condition, :grouped_scope end diff --git a/lib/grouped_scope/has_many_association.rb b/lib/grouped_scope/has_many_association.rb index 6f02b72..82785d0 100644 --- a/lib/grouped_scope/has_many_association.rb +++ b/lib/grouped_scope/has_many_association.rb @@ -12,7 +12,7 @@ def construct_sql_with_group_scope if @reflection.options[:as] # TODO: Need to add case for polymorphic :as option. else - @finder_sql = "#{table_name}.#{@reflection.primary_key_name} IN (#{@owner.group.quoted_ids})" + @finder_sql = "#{@reflection.quoted_table_name}.#{@reflection.primary_key_name} IN (#{@owner.group.quoted_ids})" @finder_sql << " AND (#{conditions})" if conditions end @counter_sql = @finder_sql