You are viewing documentation for v1.0.x. Change

update()

Description

Updates the object with the supplied properties and saves it to the database. Returns true if the object was saved successfully to the database and false otherwise.

Function Syntax

update([ properties, parameterize ])

Parameters

Parameter 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).
parameterize any No true Accepts a boolean value or a string. Set to true to use cfqueryparam on all columns or pass in a list of property names to use cfqueryparam on those only.

Examples

<!--- Get a post object and then update its title in the database --->
<cfset post = model("post").findByKey(33)>
<cfset post.update(title="New version of Wheels just released")>

<!--- Get a post object and then update its title and other properties as decided by what is pased in from the URL/form --->
<cfset post = model("post").findByKey(params.key)>
<cfset post.update(title="New version of Wheels just released", properties=params.post)>

<!--- If you have a `hasOne` association setup from `author` to `bio` you can do a scoped call (the `setBio` method below will call `aBio.update(authorId=anAuthor.id)` internally) --->
<cfset anAuthor = model("author").findByKey(params.authorId)>
<cfset aBio = model("bio").findByKey(params.bioId)>
<cfset anAuthor.setBio(aBio)>

<!--- If you have a `hasMany` association setup from `owner` to `car` you can do a scoped call (the `addCar` method below will call `aCar.update(ownerId=anOwner.id)` internally) --->
<cfset anOwner = model("owner").findByKey(params.ownerId)>
<cfset aCar = model("car").findByKey(params.carId)>
<cfset anOwner.addCar(aCar)>

<!--- If you have a `hasMany` association setup from `post` to `comment` you can do a scoped call (the `removeComment` method below will call `aComment.update(postId="")` internally) --->
<cfset aPost = model("post").findByKey(params.postId)>
<cfset aComment = model("comment").findByKey(params.commentId)>
<cfset aPost.removeComment(aComment)>