Clear ORM
Search…
Primary Keys
Clear needs your model to define a primary key column. By default, Clear can handle properly int, bigint, string and uuid primary keys.
As time of writing this manual, compound primary keys are not handled properly.

primary_key helper

Clear offers a built-in primary_key helper which will define your primary key without hassle:
1
class Product
2
include Clear::Model
3
4
self.table = "products"
5
6
primary_key name: "product_id", type: :uuid
7
end
Copied!
    name is the name of your column in your table. (Default: id)
    type is the type of the column in your table. Set to (Default: bigserial).
    By default, types can be of type bigserial, serial, int, bigint, text and uuid.
Note than primary_key directive in the model class is just a fast way of writing:
1
column id : Int64, primary: true, presence: false
Copied!
The primary key name is ID, of type bigint and it won't check the presence on save because it has default value
In case of uuid, Clear will generate a new uuid at every new object creation before inserting it into the database.
Last modified 2yr ago
Copy link