Model Configuration
setTableNamePrefix()
Signature
Section titled “Signature”setTableNamePrefix() — returns void
Available in: model
Category: Miscellaneous Functions
Description
Section titled “Description”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.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
prefix | string | yes | — | A prefix to prepend to the table name. |
Examples
Section titled “Examples”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");
}