Sha256: 652321a825dbeb096d42c3f9aab7a940b37793e66b69a1f27fc20eb68f1ad805

Contents?: true

Size: 1.23 KB

Versions: 18

Compression:

Stored size: 1.23 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
        # 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
        # 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

18 entries across 18 versions & 1 rubygems

Version Path
composite_primary_keys-14.0.9 lib/composite_primary_keys/attribute_methods/primary_key.rb
composite_primary_keys-14.0.8 lib/composite_primary_keys/attribute_methods/primary_key.rb
composite_primary_keys-13.0.8 lib/composite_primary_keys/attribute_methods/primary_key.rb
composite_primary_keys-14.0.7 lib/composite_primary_keys/attribute_methods/primary_key.rb
composite_primary_keys-14.0.6 lib/composite_primary_keys/attribute_methods/primary_key.rb
composite_primary_keys-13.0.7 lib/composite_primary_keys/attribute_methods/primary_key.rb
composite_primary_keys-13.0.6 lib/composite_primary_keys/attribute_methods/primary_key.rb
composite_primary_keys-14.0.5 lib/composite_primary_keys/attribute_methods/primary_key.rb
composite_primary_keys-13.0.5 lib/composite_primary_keys/attribute_methods/primary_key.rb
composite_primary_keys-13.0.4 lib/composite_primary_keys/attribute_methods/primary_key.rb
composite_primary_keys-14.0.4 lib/composite_primary_keys/attribute_methods/primary_key.rb
composite_primary_keys-14.0.3 lib/composite_primary_keys/attribute_methods/primary_key.rb
composite_primary_keys-13.0.3 lib/composite_primary_keys/attribute_methods/primary_key.rb
composite_primary_keys-14.0.2 lib/composite_primary_keys/attribute_methods/primary_key.rb
composite_primary_keys-13.0.2 lib/composite_primary_keys/attribute_methods/primary_key.rb
composite_primary_keys-14.0.1 lib/composite_primary_keys/attribute_methods/primary_key.rb
composite_primary_keys-13.0.1 lib/composite_primary_keys/attribute_methods/primary_key.rb
composite_primary_keys-13.0.0 lib/composite_primary_keys/attribute_methods/primary_key.rb