Skip to content
This repository
Browse code

Use Relation#apply_finder_options from calculations

  • Loading branch information...
commit f80be3ea0fa2bb3416e180901d441b0834001c7f 1 parent 61e8315
Pratik authored January 16, 2010
19  activerecord/lib/active_record/calculations.rb
@@ -163,14 +163,7 @@ def construct_calculation_arel(options = {}, merge_with_relation = nil)
163 163
             join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(self, includes, construct_join(joins))
164 164
             construct_calculation_arel_with_included_associations(options, join_dependency, merge_with_relation)
165 165
           else
166  
-            relation = active_relation.
167  
-              joins(options[:joins]).
168  
-              where(options[:conditions]).
169  
-              order(options[:order]).
170  
-              limit(options[:limit]).
171  
-              offset(options[:offset]).
172  
-              group(options[:group]).
173  
-              having(options[:having])
  166
+            relation = active_relation.apply_finder_options(options.slice(:joins, :conditions, :order, :limit, :offset, :group, :having))
174 167
 
175 168
             if merge_with_relation
176 169
               relation = merge_with_relation.except(:select, :order, :limit, :offset, :group, :from).merge(relation)
@@ -205,14 +198,8 @@ def construct_calculation_arel_with_included_associations(options, join_dependen
205 198
             relation = relation.where(type_condition) if finder_needs_type_condition?
206 199
           end
207 200
 
208  
-          relation = relation.joins(options[:joins]).
209  
-            select(column_aliases(join_dependency)).
210  
-            group(options[:group]).
211  
-            having(options[:having]).
212  
-            order(options[:order]).
213  
-            where(options[:conditions]).
214  
-            from(options[:from])
215  
-
  201
+          relation = relation.apply_finder_options(options.slice(:joins, :group, :having, :order, :conditions, :from)).
  202
+            select(column_aliases(join_dependency))
216 203
 
217 204
           if !using_limitable_reflections?(join_dependency.reflections) && (merge_limit || options[:limit])
218 205
             relation = relation.where(construct_arel_limited_ids_condition(options, join_dependency))

0 notes on commit f80be3e

Please sign in to comment.
Something went wrong with that request. Please try again.