Finally, a framework for the rest of us!

CFWheels is an open source CFML (ColdFusion Markup Language) framework inspired by Ruby on Rails that provides fast application development, a great organization system for your code, and is just plain fun to use.

One of our biggest goals is for you to be able to get up and running with CFWheels quickly. We want for you to be able to learn it as rapidly as it is to write applications with it.

Get Started    

Deleting Records

Deleting records from your database tables.

Deleting records in Wheels is simple. If you have fetched an object, you can just call its delete() method. If you don't have any callbacks specified for the class, all that will happen is that the record will be deleted from the table and true will be returned.

Delete Callbacks

If you have callbacks however, this is what happens:

First, all methods registered to be run before a delete happens (these are registered using a beforeDelete() call from the init function) will be executed, if any exist.

If these return true, Wheels will proceed and delete the record from the table. If false is returned from the callback code, processing will return to your code without the record being deleted. (false is returned to you in this case.)

If the record was deleted, the afterDelete() callback code is executed, and whatever that code returns will be returned to you. (You should make all your callbacks return true or false.)

If you're unfamiliar with the concept of callbacks, you can read about them in the Object Callbacks chapter.

Example of Deleting a Record

Here's a simple example of fetching a record from the database and then deleting it.

<cfset aPost = model("post").findByKey(33)>
<cfset aPost.delete()>

There are also 3 class-level delete methods available: deleteByKey(), deleteOne(), and deleteAll(). These work similarly to the class level methods for updating, which you can read more about in Updating Records.

Deleting Records

Deleting records from your database tables.