Model Object
isPersisted()
Signature
Section titled “Signature”isPersisted() — returns boolean
Available in: model
Category: Miscellaneous Functions
Description
Section titled “Description”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.
Examples
Section titled “Examples”// 1. Check if a newly created (unsaved) object has been persisted
user = model("User").new(firstName="Jane", lastName="Doe");
writeOutput(user.isPersisted()); // -> false
// 2. Check if an object loaded from the database is persisted
user = model("User").findByKey(1);
writeOutput(user.isPersisted()); // -> true
// 3. Check persistence after saving a new object
post = model("Post").new(title="Hello World", body="First post.");
post.save();
writeOutput(post.isPersisted()); // -> true