Skip to content

Model Object

isPersisted()

isPersisted() — returns boolean

Available in: model Category: Miscellaneous Functions

Returns true if this object has been persisted to the database or was loaded from the database via a finder. Returns false if the record has not been persisted to the database.

1. Check an older object
employee = model("employee").findByKey(123);
if (employee.isPersisted()) {
    writeOutput("This employee exists in the database.");
} else {
    writeOutput("This employee has not been saved yet.");
}

2. Creating a new object
newEmployee = model("employee").new();
if (!newEmployee.isPersisted()) {
    writeOutput("This is a new object, not yet persisted.");
}