Back

save()

Name Type Required Default Description
parameterize any No true Set to true to use cfqueryparam on all columns, or pass in a list of property names to use cfqueryparam on those only.
reload boolean No false Set to true to force Wheels to query the database even though an identical query for this model may have been run in the same request. (The default in Wheels is to get the second query from the model's request-level cache.)
validate boolean No true Set to false to skip validations for this operation.
transaction string No [runtime expression] Set this to commit to update the database, rollback to run all the database queries but not commit them, or none to skip transaction handling altogether.
callbacks boolean No true Set to false to disable callbacks for this method.
1. Basic Save (Automatic INSERT/UPDATE)

<cfscript>
user = model("user").new();
user.firstName = "Alice";
user.lastName = "Smith";
user.email = "alice@example.com";

if(user.save()){
    writeOutput("User saved successfully!");
} else {
    writeOutput("Error saving user. Please check validations.");
}
</cfscript>

2. Save Without Validations

<cfscript>
user = model("user").findByKey(1);
user.firstName = ""; // Normally fails validation

// Save without running validations
user.save(validate=false);
</cfscript>

3. Save Using Specific cfqueryparam Columns

<cfscript>
user = model("user").new();
user.firstName = "Bob";
user.lastName = "Jones";
user.email = "bob@example.com";

// Only parameterize the `email` field
user.save(parameterize="email");
</cfscript>

4. Save Within a Transaction

<cfscript>
user = model("user").new();
user.firstName = "Charlie";
user.lastName = "Brown";
user.email = "charlie@example.com";

// Attempt to save, but roll back instead of committing
user.save(transaction="rollback");
</cfscript>

5. Save and Handle Callbacks Manually

<cfscript>
user = model("user").new();
user.firstName = "Dana";
user.lastName = "White";
user.email = "dana@example.com";

// Save without triggering beforeSave/afterSave callbacks
user.save(callbacks=false);
</cfscript>
Copied!