Ticket #10254: activerecord_calculations_fix.diff
| File activerecord_calculations_fix.diff, 2.3 kB (added by bloopletech, 10 months ago) |
|---|
-
calculations.rb
old new 1 1 module ActiveRecord 2 2 module Calculations #:nodoc: 3 CALCULATIONS_OPTIONS = [:conditions, :joins, :order, :select, :group, :having, :distinct, :limit, :offset, :include ]3 CALCULATIONS_OPTIONS = [:conditions, :joins, :order, :select, :group, :having, :distinct, :limit, :offset, :include, :from] 4 4 def self.included(base) 5 5 base.extend(ClassMethods) 6 6 end … … 24 24 # * <tt>:group</tt>: An attribute name by which the result should be grouped. Uses the GROUP BY SQL-clause. 25 25 # * <tt>:select</tt>: By default, this is * as in SELECT * FROM, but can be changed if you for example want to do a join, but not 26 26 # include the joined columns. 27 # * <tt>:from</tt>: By default, this is the table name of the class, but can be changed to an alternate table name (or even the name 28 # of a database view). 27 29 # * <tt>:distinct</tt>: Set this to true to make this a distinct calculation, such as SELECT COUNT(DISTINCT posts.id) ... 28 30 # 29 31 # Examples for counting all: … … 102 104 # * <tt>:group</tt>: An attribute name by which the result should be grouped. Uses the GROUP BY SQL-clause. 103 105 # * <tt>:select</tt>: By default, this is * as in SELECT * FROM, but can be changed if you for example want to do a join, but not 104 106 # include the joined columns. 107 # * <tt>:from</tt>: By default, this is the table name of the class, but can be changed to an alternate table name (or even the name 108 # of a database view). 105 109 # * <tt>:distinct</tt>: Set this to true to make this a distinct calculation, such as SELECT COUNT(DISTINCT posts.id) ... 106 110 # 107 111 # Examples: … … 178 182 179 183 sql << ", #{options[:group_field]} AS #{options[:group_alias]}" if options[:group] 180 184 sql << " FROM (SELECT DISTINCT #{column_name}" if use_workaround 181 sql << " FROM #{ table_name} "185 sql << " FROM #{options[:from] || table_name} " 182 186 if merged_includes.any? 183 187 join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(self, merged_includes, options[:joins]) 184 188 sql << join_dependency.join_associations.collect{|join| join.association_join }.join