Module: TypedUUID::PsqlColumnMethods

Defined in:
lib/typed_uuid/psql_column_methods.rb

Instance Method Summary collapse

Instance Method Details

#primary_key(name, type = :primary_key, **options) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/typed_uuid/psql_column_methods.rb', line 3

def primary_key(name, type = :primary_key, **options)
  if type == :typed_uuid
    klass_type_enum = ::ActiveRecord::Base.uuid_enum_from_table_name(self.name)
    klass_type_version = ::ActiveRecord::Base.uuid_version_from_table_name(self.name)
    options[:default] ||= -> { "typed_uuid(#{klass_type_enum}, #{klass_type_version})" }
    super(name, :uuid, **options)
  else
    super
  end
end