Sha256: e7e7120b4fddeb71d4b66f4f0b2fb7fbbbc820f86181ef9d19a0b81abf0317f1

Contents?: true

Size: 1.3 KB

Versions: 7

Compression:

Stored size: 1.3 KB

Contents

module ActiveRecord
  module AttributeMethods
    module PrimaryKey
      module ClassMethods
        def suppress_composite_primary_key(pk)
          pk
          # return pk unless pk.is_a?(Array)
          #
          # warn <<~WARNING
          #         WARNING: Active Record does not support composite primary key.
          #
          #         #{table_name} has composite primary key. Composite primary key is ignored.
          # WARNING
        end
      end

      # Returns the primary key previous value.
      def id_was
        sync_with_transaction_state
        # CPK
        # attribute_was(self.class.primary_key)
        if self.composite?
          self.class.primary_keys.map do |key_attr|
            attribute_changed?(key_attr) ? changed_attributes[key_attr] : self.ids_hash[key_attr]
          end
        else
          attribute_was(self.class.primary_key)
        end
      end

      def id_in_database
        sync_with_transaction_state
        # CPK
        # attribute_in_database(self.class.primary_key)
        if self.composite?
          self.class.primary_keys.map do |key_attr|
            attribute_in_database(key_attr)
          end
        else
          attribute_in_database(self.class.primary_key)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
composite_primary_keys-12.0.10 lib/composite_primary_keys/attribute_methods/primary_key.rb
composite_primary_keys-12.0.9 lib/composite_primary_keys/attribute_methods/primary_key.rb
composite_primary_keys-12.0.8 lib/composite_primary_keys/attribute_methods/primary_key.rb
composite_primary_keys-12.0.6 lib/composite_primary_keys/attribute_methods/primary_key.rb
composite_primary_keys-12.0.5 lib/composite_primary_keys/attribute_methods/primary_key.rb
composite_primary_keys-12.0.4 lib/composite_primary_keys/attribute_methods/primary_key.rb
composite_primary_keys-12.0.3 lib/composite_primary_keys/attribute_methods/primary_key.rb