Model Configuration
protectedProperties()
Signature
Section titled “Signature”protectedProperties() — returns void
Available in: model
Category: Miscellaneous Functions
Description
Section titled “Description”Used to protect one or more model properties from being set or modified through mass assignment operations. Mass assignment occurs when values are assigned to a model in bulk, such as through create(), update(), or updateAll() using a struct of data. By marking certain properties as protected, you can prevent accidental or malicious changes to sensitive fields (such as id, role, or passwordHash). This method is typically called in the model’s config() function to define rules that apply across the entire model.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
properties | string | no | — | Property name (or list of property names) that are not allowed to be altered through mass assignment. |
Examples
Section titled “Examples”// In `app/models/User.cfc`, `firstName` and `lastName` cannot be changed through mass assignment operations like `updateAll()`.
function config(){
protectedProperties("firstName,lastName");
}