updateOne()
Description
Gets an object based on the arguments used and updates it with the supplied properties. Returns true if an object was found and updated successfully, false otherwise.
Function Syntax
updateOne([ where, order, properties ])
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
where |
string |
No | |
This argument maps to the WHERE clause of the query. The following operators are supported: =, <>, <, <=, >, >=, LIKE, AND, and OR (note that the key words have to be written in upper case). You can also use parentheses to group statements. You do not have to specify the table name(s), Wheels will do that for you. |
order |
string |
No | |
This argument maps to the ORDER BY clause of the query. You do not have to specify the table name(s), Wheels will do that for you. |
properties |
struct |
No | [runtime expression] |
The properties you want to set on the object (can also be passed in as named arguments). |
Examples
<!--- Sets the `new` property to `1` on the most recently released product --->
<cfset result = model("product").updateOne(order="releaseDate DESC", new=1)>
<!--- If you have a `hasOne` association setup from `user` to `profile` you can do a scoped call (the `removeProfile` method below will call `model("profile").updateOne(where="userId=#aUser.id#", userId="")` internally) --->
<cfset aUser = model("user").findByKey(params.userId)>
<cfset aUser.removeProfile()>
