Migrator
updateRecord()
Signature
Section titled “Signature”updateRecord() — returns void
Available in: migration
Category: Migration Functions
Description
Section titled “Description”Updates an existing record in a table Only available in a migration CFC
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
table | string | yes | — | The table name where the record is |
where | string | no | — | The where clause, i.e admin = 1. Raw SQL — callers must supply a predicate or all=true. |
all | boolean | no | false | When true, an empty where updates every row. Default false (fail-closed). |
Examples
Section titled “Examples”// 1. Update a single column for all rows in a table
updateRecord(
table = "settings",
value = "My Updated App"
);
// 2. Update specific columns using a where clause to target matching rows
updateRecord(
table = "users",
where = "role = 'guest'",
active = false
);
// 3. Update multiple columns during a migration's up() function
component extends="wheels.migrator.Migration" {
function up() {
updateRecord(
table = "users",
where = "id = 1",
firstName = "Bruce",
lastName = "Wayne",
email = "bruce@wayneenterprises.com"
);
}
function down() {
updateRecord(
table = "users",
where = "id = 1",
firstName = "Clark",
lastName = "Kent",
email = "clark@dailyplanet.com"
);
}
}