Ticket #10254: activerecord_calculations_from_(fix).diff
| File activerecord_calculations_from_(fix).diff, 2.5 kB (added by michaelboutros, 8 months ago) |
|---|
-
activerecord/lib/active_record/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 … … 26 26 # * <tt>:group</tt>: An attribute name by which the result should be grouped. Uses the GROUP BY SQL-clause. 27 27 # * <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 28 28 # include the joined columns. 29 # * <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 30 # of a database view). 29 31 # * <tt>:distinct</tt>: Set this to true to make this a distinct calculation, such as SELECT COUNT(DISTINCT posts.id) ... 30 32 # 31 33 # Examples for counting all: … … 104 106 # * <tt>:group</tt> - An attribute name by which the result should be grouped. Uses the GROUP BY SQL-clause. 105 107 # * <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 106 108 # include the joined columns. 109 # * <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 110 # of a database view). 107 111 # * <tt>:distinct</tt> - Set this to true to make this a distinct calculation, such as SELECT COUNT(DISTINCT posts.id) ... 108 112 # 109 113 # Examples: … … 174 178 175 179 sql << ", #{options[:group_field]} AS #{options[:group_alias]}" if options[:group] 176 180 sql << " FROM (SELECT DISTINCT #{column_name}" if use_workaround 177 sql << " FROM #{ connection.quote_table_name(table_name)} "181 sql << " FROM #{options[:from] || connection.quote_table_name(table_name)} " 178 182 if merged_includes.any? 179 183 join_dependency = ActiveRecord::Associations::ClassMethods::JoinDependency.new(self, merged_includes, options[:joins]) 180 184 sql << join_dependency.join_associations.collect{|join| join.association_join }.join