aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2012-04-13 13:12:28 +0100
committerJon Leighton <j@jonathanleighton.com>2012-04-13 13:17:43 +0100
commitbe89e9a35162b3015e2aee53300fdf04752652ce (patch)
tree35aad2aa257da5a1f416da2be1a98e03c4ba4337
parent8d5be98ad72939037f1be52aa4bb4672fff02abb (diff)
downloadrails-be89e9a35162b3015e2aee53300fdf04752652ce.tar.gz
rails-be89e9a35162b3015e2aee53300fdf04752652ce.tar.bz2
rails-be89e9a35162b3015e2aee53300fdf04752652ce.zip
remove apply_finder_options call from AssociationScope
-rw-r--r--activerecord/lib/active_record/associations/association_scope.rb15
-rw-r--r--activerecord/lib/active_record/relation/merger.rb2
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb2
-rw-r--r--activerecord/test/cases/relation_test.rb5
4 files changed, 15 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb
index 2972b7e13e..5a44d3a156 100644
--- a/activerecord/lib/active_record/associations/association_scope.rb
+++ b/activerecord/lib/active_record/associations/association_scope.rb
@@ -15,19 +15,20 @@ module ActiveRecord
def scope
scope = klass.unscoped
- scope = scope.extending(*Array(options[:extend]))
+
+ scope.extending!(*Array(options[:extend]))
# It's okay to just apply all these like this. The options will only be present if the
# association supports that option; this is enforced by the association builder.
- scope = scope.apply_finder_options(options.slice(
- :readonly, :include, :references, :order, :limit, :joins, :group, :having, :offset, :select))
+ scope.merge!(options.slice(
+ :readonly, :references, :order, :limit, :joins, :group, :having, :offset, :select, :uniq))
- if options[:through] && !options[:include]
- scope = scope.includes(source_options[:include])
+ if options[:include]
+ scope.includes! options[:include]
+ elsif options[:through]
+ scope.includes! source_options[:include]
end
- scope = scope.uniq if options[:uniq]
-
add_constraints(scope)
end
diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb
index b6fdb23066..0a5e9ef171 100644
--- a/activerecord/lib/active_record/relation/merger.rb
+++ b/activerecord/lib/active_record/relation/merger.rb
@@ -69,7 +69,7 @@ module ActiveRecord
relation.reorder! values[:order]
elsif values[:order]
# merge in order_values from r
- relation.order_values += values[:order]
+ relation.order! values[:order]
end
relation.extend(*values[:extending]) unless values[:extending].blank?
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index eaa3ddaec8..ffca88f69f 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -356,7 +356,7 @@ module ActiveRecord
modules << Module.new(&block) if block_given?
self.extending_values = modules.flatten
- extend(*extending_values)
+ extend(*extending_values) if extending_values.any?
self
end
diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb
index fdd8e2112e..633654a961 100644
--- a/activerecord/test/cases/relation_test.rb
+++ b/activerecord/test/cases/relation_test.rb
@@ -176,6 +176,11 @@ module ActiveRecord
assert relation.is_a?(mod)
end
+ test 'extending! with empty args' do
+ relation.extending!
+ assert_equal [], relation.extending_values
+ end
+
(Relation::SINGLE_VALUE_METHODS - [:lock, :reordering, :reverse_order, :create_with]).each do |method|
test "##{method}!" do
assert relation.public_send("#{method}!", :foo).equal?(relation)