Model Configuration
beforeSave()
Signature
Section titled “Signature”beforeSave() — returns void
Available in: model
Category: Callback Functions
Description
Section titled “Description”Registers method(s) that should be called before an object is saved.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
methods | string | no | — | Method name or list of method names that should be called when this callback event occurs in an object’s life cycle (can also be called with the method argument). |
Examples
Section titled “Examples”// 1. Call a single method before every save (create or update)
// In models/User.cfc
component extends="Model" {
function config() {
beforeSave("normalizeEmail");
}
private function normalizeEmail() {
this.email = LCase(Trim(this.email));
}
}
// 2. Register multiple callback methods as a comma-delimited list
component extends="Model" {
function config() {
beforeSave("stripWhitespace,generateSlug");
}
}
// 3. Use the `method` argument alias to register a single callback
component extends="Model" {
function config() {
beforeSave(method="sanitizeContent");
}
}