Back
delete()
Example 1: Delete a single object
<cfscript>
post = model("post").findByKey(33);
success = post.delete();
</cfscript>
Deletes the post with ID 33 from the database.
Returns true if deletion succeeds.
Example 2: Scoped delete via association
<cfscript>
post = model("post").findByKey(params.postId);
comment = model("comment").findByKey(params.commentId);
// Calls comment.delete() internally
post.deleteComment(comment);
</cfscript>
If post has a hasMany association to comment, this uses the association method to delete a related comment.
Example 3: Permanent deletion (bypass soft-delete)
<cfscript>
post = model("post").findByKey(33);
post.delete(softDelete=false);
</cfscript>
Forces a hard delete even if the model uses soft-delete columns.
Copied!