Model Class
findFirst()
Signature
Section titled “Signature”findFirst() — returns any
Available in: model
Category: Read Functions
Description
Section titled “Description”Fetches the first record ordered by primary key value.
Use the property argument to order by something else.
Returns a model object.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
property | string | no | [runtime expression] | Name of the property to order by. This argument is also aliased as properties. |
$sort | string | no | ASC |
Examples
Section titled “Examples”// 1. Get the first user record (ordered by primary key ascending)
user = model("User").findFirst();
// Returns the model object with the lowest primary key value, or false if no records exist.
// 2. Get the first user ordered by a specific property
user = model("User").findFirst(property="createdAt");
// Returns the oldest user (lowest createdAt value).
// 3. Get the first active user ordered by last name, then first name
user = model("User").findFirst(properties="lastName,firstName", where="active = 1");
// Equivalent to: ORDER BY lastName ASC, firstName ASC with a WHERE clause applied.
// Returns a model object, or false if no matching record is found.