Model Class
findLastOne()
Signature
Section titled “Signature”findLastOne() — returns any
Available in: model
Category: Read Functions
Description
Section titled “Description”Fetches the last record ordered by primary key value.
Use the property argument to order by something else.
Returns a model object. Formerly known as findLast.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
property | string | no | — | Name of the property to order by. This argument is also aliased as properties. |
Examples
Section titled “Examples”// 1. Get the last user record (ordered by primary key descending)
lastUser = model("User").findLastOne();
// Returns a User object for the record with the highest primary key, or false if none exist.
// 2. Get the most recently created post by ordering on a different property
latestPost = model("Post").findLastOne(property="createdAt");
// Returns the Post object with the latest createdAt value.
// 3. Get the last active product, using a where clause alongside the property order
lastActive = model("Product").findLastOne(property="updatedAt", where="isActive = 1");
// Returns the most recently updated active product, or false if none exist.