Macro used to define serializable primary keys.
Currently support bigserial
, serial
and uuid
.
For bigserial
and serial
, let to PostgreSQL the handling of sequence numbers.
For uuid
, will generate a new UUID
number on creation.
{"bigserial" => "column(__name__ : Int64, primary: true, presence: false)", "serial" => "column(__name__ : Int32, primary: true, presence: false)", "text" => "column(__name__ : String, primary: true, presence: true)", "int" => "column(__name__ : Int32, primary: true, presence: true)", "bigint" => "column(__name__ : Int64, primary: true, presence: true)", "uuid" => "column(__name__ : UUID, primary: true, presence: true)\nbefore(:validate) do |m|\n if (!m.persisted?) && (m.as(self)).__name___column.value(nil).nil?\n (m.as(self)).__name__ = UUID.random\n end\nend\n"} of Nil => Nil
Add a hook for the primary_key
In the hook, name will be replaced by the column name required by calling primary_key
Macro used to define serializable primary keys.
Add a hook for the primary_key
In the hook, name will be replaced by the column name required by calling primary_key
Clear::Model::HasSerialPkey.add_pkey_type("awesomepkey") do
column __name__ : AwesomePkey, primary: true, presence: false
before_validate do
# ...
end
end
Your new primary key system can then be called using primary_key
method:
primary_key :id, :awesomepkey
Macro used to define serializable primary keys.
Currently support bigserial
, serial
and uuid
.
For bigserial
and serial
, let to PostgreSQL the handling of sequence numbers.
For uuid
, will generate a new UUID
number on creation.