Skip to content

Model Configuration

setTableNamePrefix()

setTableNamePrefix() — returns void

Available in: model Category: Miscellaneous Functions

Allows you to add a prefix to the table name used by a model when performing SQL queries. This is useful if your database uses a consistent naming convention, such as tblUsers instead of Users. By default, Wheels infers the table name from the model name (e.g., User -> users). Using a prefix ensures that all queries automatically reference the correctly prefixed table.

NameTypeRequiredDefaultDescription
prefixstringyesA prefix to prepend to the table name.
1. Basic prefix
// In app/models/User.cfc
function config(){
    // All queries will now target 'tblUsers' instead of 'users'
    setTableNamePrefix("tbl");
}

2. Using a custom prefix for multiple models
// app/models/Product.cfc
function config(){
    setTableNamePrefix("tbl");
}

// app/models/Order.cfc
function config(){
    setTableNamePrefix("tbl");
}