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_enum = ::ActiveRecord::Base.uuid_type_from_table_name(self.name)
    options[:id] = :uuid
    options[:default] ||= -> { "typed_uuid('\\x#{klass_enum.to_s(16).rjust(4, '0')}')" }
    super(name, :uuid, **options)
  else
    super
  end
end