Sha256: 5900034e99d53e9f332161680982e2f50deedb75e763c534304d19257af5cfa8

Contents?: true

Size: 1.38 KB

Versions: 14

Compression:

Stored size: 1.38 KB

Contents

module ActiveRecord
  module Transactions
    # Restore the new record state and id of a record that was previously saved by a call to save_record_state.
    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]
          @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

          # CPK
          if self.composite?
            values = @primary_key.map {|attribute| @attributes.fetch_value(attribute)}
            restore_id = restore_state[:id]
            if values != restore_id
              @primary_key.each_with_index do |attribute, i|
                @attributes.write_from_user(attribute, restore_id[i])
              end
            end
          elsif @attributes.fetch_value(@primary_key) != restore_state[:id]
            @attributes.write_from_user(@primary_key, restore_state[:id])
          end
          freeze if restore_state[:frozen?]
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
composite_primary_keys-13.0.1 lib/composite_primary_keys/transactions.rb
composite_primary_keys-13.0.0 lib/composite_primary_keys/transactions.rb
composite_primary_keys-12.0.10 lib/composite_primary_keys/transactions.rb
composite_primary_keys-12.0.9 lib/composite_primary_keys/transactions.rb
composite_primary_keys-12.0.8 lib/composite_primary_keys/transactions.rb
composite_primary_keys-12.0.6 lib/composite_primary_keys/transactions.rb
composite_primary_keys-12.0.5 lib/composite_primary_keys/transactions.rb
composite_primary_keys-12.0.4 lib/composite_primary_keys/transactions.rb
composite_primary_keys-12.0.3 lib/composite_primary_keys/transactions.rb
composite_primary_keys-12.0.2 lib/composite_primary_keys/transactions.rb
composite_primary_keys-12.0.1 lib/composite_primary_keys/transactions.rb
composite_primary_keys-12.0.0 lib/composite_primary_keys/transactions.rb
composite_primary_keys-12.0.0.rc5 lib/composite_primary_keys/transactions.rb
composite_primary_keys-12.0.0.rc4 lib/composite_primary_keys/transactions.rb