Module: ActiveRecord::Calculations
- Defined in:
- lib/left_joins_for_rails_3.rb,
lib/left_joins.rb
Instance Method Summary collapse
- #distinct_value ⇒ Object
- #distinct_value=(v) ⇒ Object
-
#perform_calculation(operation, column_name, options = {}) ⇒ Object
This method is copied from activerecord-4.2.10/lib/active_record/relation/calculations.rb and modified this line ‘distinct = true` to `distinct = true if distinct == nil`.
Instance Method Details
#distinct_value ⇒ Object
13 14 15 |
# File 'lib/left_joins_for_rails_3.rb', line 13 def distinct_value uniq_value end |
#distinct_value=(v) ⇒ Object
17 18 19 |
# File 'lib/left_joins_for_rails_3.rb', line 17 def distinct_value=(v) self.uniq_value = v end |
#perform_calculation(operation, column_name, options = {}) ⇒ Object
This method is copied from activerecord-4.2.10/lib/active_record/relation/calculations.rb and modified this line ‘distinct = true` to `distinct = true if distinct == nil`
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/left_joins.rb', line 98 def perform_calculation(operation, column_name, = {}) # TODO: Remove options argument as soon we remove support to # activerecord-deprecated_finders. operation = operation.to_s.downcase # If #count is used with #distinct / #uniq it is considered distinct. (eg. relation.distinct.count) distinct = [:distinct] || self.distinct_value if operation == "count" column_name ||= (select_for_count || :all) unless arel.ast.grep(Arel::Nodes::OuterJoin).empty? distinct = true if distinct == nil end column_name = primary_key if column_name == :all && distinct distinct = nil if column_name =~ /\s*DISTINCT[\s(]+/i end if group_values.any? execute_grouped_calculation(operation, column_name, distinct) else execute_simple_calculation(operation, column_name, distinct) end end |