Return to v2.5.0 docs

save()


Model Class CRUD Functions boolean model


Saves the object if it passes validation and callbacks. Returns true if the object was saved successfully to the database, false if not.

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 CFWheels to query the database even though an identical query for this model may have been run in the same request. (The default in CFWheels 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.
// Save the user object to the database (will automatically do an `INSERT` or `UPDATE` statement depending on if the record is new or already exists
user.save();

// Save the user object directly in an if statement without using `cfqueryparam` and take appropriate action based on the result
if(user.save(parameterize=false)){
	flashInsert(notice="The user was saved!");
	redirectTo(action="edit");
} else {
	flashInsert(alert="Error, please correct!");
	renderView(action="edit");
}

Related Functions

CRUD Functions