Restore the new record state and id of a record that was previously saved
by a call to save_record_state.
# File activerecord/lib/active_record/transactions.rb, line 414
def restore_transaction_record_state(force_restore_state = false)
if restore_state = @_start_transaction_state
if force_restore_state || restore_state[:level] <= 1
@new_record = restore_state[:new_record]
@previously_new_record = restore_state[:previously_new_record]
@destroyed = restore_state[:destroyed]
@attributes = restore_state[:attributes].map do |attr|
value = @attributes.fetch_value(attr.name)
attr = attr.with_value_from_user(value) if attr.value != value
attr
end
@mutations_from_database = nil
@mutations_before_last_save = nil
if self.class.composite_primary_key?
if restore_state[:id] != @primary_key.map { |col| @attributes.fetch_value(col) }
@primary_key.zip(restore_state[:id]).each do |col, val|
@attributes.write_from_user(col, val)
end
end
else
if @attributes.fetch_value(@primary_key) != restore_state[:id]
@attributes.write_from_user(@primary_key, restore_state[:id])
end
end
freeze if restore_state[:frozen?]
end
end
end