Module: ActiveRecord::QueryMethods
- Defined in:
- lib/active_record/query_methods.rb
Instance Method Summary collapse
- #build_arel_with_distinct_on(aliases = nil) ⇒ Object (also: #build_arel)
- #distinct_on(*fields) ⇒ Object (also: #uniq_on)
- #distinct_on!(*fields) ⇒ Object (also: #uniq_on!)
- #distinct_on_values ⇒ Object
- #distinct_on_values=(value) ⇒ Object
Instance Method Details
#build_arel_with_distinct_on(aliases = nil) ⇒ Object Also known as: build_arel
27 28 29 30 31 |
# File 'lib/active_record/query_methods.rb', line 27 def build_arel_with_distinct_on(aliases = nil) arel = build_arel_without_distinct_on(aliases) arel.distinct_on(self.distinct_on_values) if !self.distinct_on_values.empty? arel end |
#distinct_on(*fields) ⇒ Object Also known as: uniq_on
15 16 17 |
# File 'lib/active_record/query_methods.rb', line 15 def distinct_on(*fields) spawn.distinct_on!(*fields) end |
#distinct_on!(*fields) ⇒ Object Also known as: uniq_on!
20 21 22 23 24 |
# File 'lib/active_record/query_methods.rb', line 20 def distinct_on!(*fields) fields.flatten! self.distinct_on_values = fields.map { |x| x.is_a?(Arel::Attributes::Attribute) ? x : klass.arel_table[x] } self end |
#distinct_on_values ⇒ Object
7 8 9 |
# File 'lib/active_record/query_methods.rb', line 7 def distinct_on_values @values["distinct_on_values"] || [] end |
#distinct_on_values=(value) ⇒ Object
11 12 13 |
# File 'lib/active_record/query_methods.rb', line 11 def distinct_on_values=(value) @values["distinct_on_values"] = value end |