deleteAll()
Description
Deletes all records that match the where argument. By default objects will not be instantiated and therefore callbacks and validations are not invoked. You can change this behavior by passing in instantiate=true. Returns the number of records that were deleted.
Function Syntax
deleteAll([ where, include, parameterize, instantiate ])
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
where |
string |
No | |
This argument maps to the WHERE clause of the query. The following operators are supported: =, <>, <, <=, >, >=, LIKE, AND, and OR (note that the key words have to be written in upper case). You can also use parentheses to group statements. You do not have to specify the table name(s), Wheels will do that for you. |
include |
string |
No | |
Associations that should be included in the query using INNER or LEFT OUTER joins (which join type that is used depends on how the association has been set up in your model). If all included associations are set on the current model you can specify them in a list, e.g. department,addresses,emails. You can build more complex include strings by using parentheses when the association is set on an included model, like album(artist(genre)) for example. |
parameterize |
any |
No | true |
Accepts a boolean value or a string. Set to true to use cfqueryparam on all columns or pass in a list of property names to use cfqueryparam on those only. |
instantiate |
boolean |
No | false |
Whether or not to instantiate the object(s) first. When objects are not instantiated any callbacks and validations set on them will be skipped. |
Examples
<!--- Delete all inactive users without instantiating them (will skip validation and callbacks) --->
<cfset recordsDeleted = model("user").deleteAll(where="inactive=1", instantiate=false)>
<!--- If you have a `hasMany` association setup from `post` to `comment` you can do a scoped call (the `deleteAllComments` method below will call `model("comment").deleteAll(where="postId=#post.id#")` internally) --->
<cfset aPost = model("post").findByKey(params.postId)>
<cfset howManyDeleted = aPost.deleteAllComments()>
