method
find_unique_index_for

v7.1.3.2 -
Show latest stable
-
0 notes -
Class: InsertAll
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- What's this?
find_unique_index_for(unique_by)
private
Hide source
# File activerecord/lib/active_record/insert_all.rb, line 145 def find_unique_index_for(unique_by) if !connection.supports_insert_conflict_target? return if unique_by.nil? raise ArgumentError, "#{connection.class} does not support :unique_by" end name_or_columns = unique_by || model.primary_key match = Array(name_or_columns).map(&:to_s) sorted_match = match.sort if index = unique_indexes.find { |i| match.include?(i.name) || Array(i.columns).sort == sorted_match } index elsif match == primary_keys unique_by.nil? ? nil : ActiveRecord::ConnectionAdapters::IndexDefinition.new(model.table_name, "#{model.table_name}_primary_key", true, match) else raise ArgumentError, "No unique index found for #{name_or_columns}" end end