method

replace_keys

replace_keys(record, force: false)
private

No documentation available.

# File activerecord/lib/active_record/associations/belongs_to_association.rb, line 126
        def replace_keys(record, force: false)
          reflection_fk = reflection.foreign_key
          if reflection_fk.is_a?(Array)
            target_key_values = record ? Array(primary_key(record.class)).map { |key| record._read_attribute(key) } : []

            if force || reflection_fk.map { |fk| owner._read_attribute(fk) } != target_key_values
              reflection_fk.each_with_index do |key, index|
                owner[key] = target_key_values[index]
              end
            end
          else
            target_key_value = record ? record._read_attribute(primary_key(record.class)) : nil

            if force || owner._read_attribute(reflection_fk) != target_key_value
              owner[reflection_fk] = target_key_value
            end
          end
        end