Model Object
setProperties()
Signature
Section titled “Signature”setProperties() — returns void
Available in: model
Category: Miscellaneous Functions
Description
Section titled “Description”Allows you to set multiple properties of a model object at once. It is useful when you want to update a model with a structure (struct) of key/value pairs instead of assigning each property individually. The keys of the struct should match the property names of the model. You can also pass named arguments directly instead of a struct.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
properties | struct | no | [runtime expression] | The properties you want to set on the object (can also be passed in as named arguments). |
Examples
Section titled “Examples”1. Using a struct (common scenario with form submission)
// Controller code: create new user
user = model("user").new();
// Set properties from a submitted form
user.setProperties(params.user);
// Save the updated user
user.save();
2. Using named arguments
user = model("user").new();
// Set properties directly using named arguments
user.setProperties(
firstName="John",
lastName="Doe",
email="john.doe@example.com"
);
// Save changes
user.save();
3. Using with validations
user = model("user").new();
// Set multiple properties, skipping one intentionally
user.setProperties({
firstName = "Jane",
lastName = "Smith"
});
// Only save if validations pass
if(user.save()){
writeOutput("User updated successfully!");
} else {
writeDump(user.errors);
}