Skip to content

Migrator

updateRecord()

updateRecord() — returns void

Available in: migration Category: Migration Functions

Updates an existing record in a table Only available in a migration CFC

NameTypeRequiredDefaultDescription
tablestringyes—The table name where the record is
wherestringno—The where clause, i.e admin = 1. Raw SQL — callers must supply a predicate or all=true.
allbooleannofalseWhen true, an empty where updates every row. Default false (fail-closed).
// 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"
        );
    }
}