Sha256: a7a3b3949f1d5071bc36e48f7a80273e1740a30c3d4e9ec003803513cab79ce4
Contents?: true
Size: 1.22 KB
Versions: 31
Compression:
Stored size: 1.22 KB
Contents
# frozen_string_literal: true module Torque module PostgreSQL module Relation module DistinctOn # :nodoc: def distinct_on_values; get_value(:distinct_on); end # :nodoc: def distinct_on_values=(value); set_value(:distinct_on, value); end # Specifies whether the records should be unique or not by a given set # of fields. For example: # # User.distinct_on(:name) # # Returns 1 record per distinct name # # User.distinct_on(:name, :email) # # Returns 1 record per distinct name and email # # User.distinct_on(false) # # You can also remove the uniqueness def distinct_on(*value) spawn.distinct_on!(*value) end # Like #distinct_on, but modifies relation in place. def distinct_on!(*value) self.distinct_on_values = value self end private # Hook arel build to add the distinct on clause def build_arel(*) arel = super value = self.distinct_on_values arel.distinct_on(resolve_column(value)) if value.present? arel end end end end end
Version data entries
31 entries across 31 versions & 1 rubygems