Model Configuration
afterFind()
Signature
Section titled “Signature”afterFind() — returns void
Available in: model
Category: Callback Functions
Description
Section titled “Description”Registers method(s) that should be called after an existing object has been initialized (which is usually done with the findByKey or findOne method).
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. Register a single callback method to run after records are fetched
// In models/User.cfc
config() {
afterFind("setFetchedAt");
}
// The callback receives each row's columns as arguments; return the struct to modify the record.
function setFetchedAt() {
arguments.fetchedAt = Now();
return arguments;
}
// 2. Format a column value after a find (works for both query rows and objects)
// In models/Product.cfc
config() {
afterFind("formatPrice");
}
function formatPrice() {
if (StructKeyExists(arguments, "price")) {
arguments.price = DollarFormat(arguments.price);
}
return arguments;
}
// 3. Register multiple callback methods as a comma-delimited list
config() {
afterFind("setFetchedAt,formatPrice");
}