Model Class
primaryKeys()
Signature
Section titled “Signature”primaryKeys() — returns string
Available in: model
Category: Miscellaneous Functions
Description
Section titled “Description”Alias for primaryKey().
Use this for better readability when you’re accessing multiple primary keys.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
position | numeric | no | 0 | If you are accessing a composite primary key, pass the position of a single key to fetch. |
Examples
Section titled “Examples”1. Get the primary key of a simple table
// Employees table has "id" as primary key
keyNames = model("employee").primaryKeys();
// Returns: "id"
2. Composite primary keys (order_products table with order_id + product_id)
keys = model("orderProduct").primaryKeys();
// Returns: "order_id,product_id"
3. Get only the first key in a composite primary key
firstKey = model("orderProduct").primaryKeys(position=1);
// Returns: "order_id"
4. Get only the second key in a composite primary key
secondKey = model("orderProduct").primaryKeys(position=2);
// Returns: "product_id"
5. Using alias for clarity in multi-key situations
// This makes it more obvious the table has multiple keys
keys = model("orderProduct").primaryKeys();
// Easier to read than using model("orderProduct").primaryKey()