method

distinct_relation_for_primary_key

Importance_0
v7.0.0 - Show latest stable - 0 notes - Class: ActiveRecord::ConnectionAdapters::SchemaStatements
distinct_relation_for_primary_key(relation) public

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 1292
      def distinct_relation_for_primary_key(relation) # :nodoc:
        values = columns_for_distinct(
          visitor.compile(relation.table[relation.primary_key]),
          relation.order_values
        )

        limited = relation.reselect(values).distinct!
        limited_ids = select_rows(limited.arel, "SQL").map(&:last)

        if limited_ids.empty?
          relation.none!
        else
          relation.where!(relation.primary_key => limited_ids)
        end

        relation.limit_value = relation.offset_value = nil
        relation
      end
Register or log in to add new notes.