Permalink
Browse files

Use Relation#apply_finder_options from calculations

  • Loading branch information...
1 parent 61e8315 commit f80be3ea0fa2bb3416e180901d441b0834001c7f @lifo lifo committed Jan 16, 2010
Showing with 3 additions and 16 deletions.
  1. +3 −16 activerecord/lib/active_record/calculations.rb
@@ -163,14 +163,7 @@ def construct_calculation_arel(options = {}, merge_with_relation = nil)
join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(self, includes, construct_join(joins))
construct_calculation_arel_with_included_associations(options, join_dependency, merge_with_relation)
else
- relation = active_relation.
- joins(options[:joins]).
- where(options[:conditions]).
- order(options[:order]).
- limit(options[:limit]).
- offset(options[:offset]).
- group(options[:group]).
- having(options[:having])
+ relation = active_relation.apply_finder_options(options.slice(:joins, :conditions, :order, :limit, :offset, :group, :having))
if merge_with_relation
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
relation = relation.where(type_condition) if finder_needs_type_condition?
end
- relation = relation.joins(options[:joins]).
- select(column_aliases(join_dependency)).
- group(options[:group]).
- having(options[:having]).
- order(options[:order]).
- where(options[:conditions]).
- from(options[:from])
-
+ relation = relation.apply_finder_options(options.slice(:joins, :group, :having, :order, :conditions, :from)).
+ select(column_aliases(join_dependency))
if !using_limitable_reflections?(join_dependency.reflections) && (merge_limit || options[:limit])
relation = relation.where(construct_arel_limited_ids_condition(options, join_dependency))

0 comments on commit f80be3e

Please sign in to comment.