Skip to content

Model Configuration

afterFind()

afterFind() — returns void

Available in: model Category: Callback Functions

Registers method(s) that should be called after an existing object has been initialized (which is usually done with the findByKey or findOne method).

NameTypeRequiredDefaultDescription
methodsstringno—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).
// 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");
}