Skip to content

Model Configuration

validateOnUpdate()

validateOnUpdate() — returns void

Available in: model Category: Validation Functions

Registers method(s) that should be called to validate existing objects before they are updated.

NameTypeRequiredDefaultDescription
methodsstringno—Method name or list of method names to call. Can also be called with the method argument.
conditionstringno—String expression to be evaluated that decides if validation will be run (if the expression returns true validation will run).
unlessstringno—String expression to be evaluated that decides if validation will be run (if the expression returns false validation will run).
// 1. Register a single custom validation method to run only on updates
component extends="Model" {
	function config() {
		validateOnUpdate("checkPhoneNumber");
	}

	private boolean function checkPhoneNumber() {
		// Make sure area code is 614
		return Left(this.phoneNumber, 3) == "614";
	}
}

// 2. Register multiple custom validation methods for updates
component extends="Model" {
	function config() {
		validateOnUpdate(methods="checkStatus,checkExpiry");
	}

	private boolean function checkStatus() {
		return ListFindNoCase("active,pending,suspended", this.status);
	}

	private boolean function checkExpiry() {
		return this.expiresAt > Now();
	}
}

// 3. Only validate when a condition is met (run only for premium accounts)
component extends="Model" {
	function config() {
		validateOnUpdate(methods="checkBillingAddress", condition="this.accountType eq 'premium'");
	}

	private boolean function checkBillingAddress() {
		return Len(Trim(this.billingAddress)) GT 0;
	}
}