Skip to content

Commit

Permalink
[Rails2.3] Change #attribute_condition to work which now has multiple…
Browse files Browse the repository at this point in the history
… args in 2.3.
  • Loading branch information
metaskills committed May 6, 2009
1 parent 85a743e commit 59feaeb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/grouped_scope.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'active_record/version'
require 'grouped_scope/errors'
require 'grouped_scope/grouping'
require 'grouped_scope/self_grouping'
Expand Down
18 changes: 13 additions & 5 deletions lib/grouped_scope/core_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/grouped_scope/has_many_association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 59feaeb

Please sign in to comment.