diff options
Diffstat (limited to 'activerecord')
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) |