Model Configuration
setTableNamePrefix()
Signature
Section titled “Signature”setTableNamePrefix() — returns void
Available in: model
Category: Miscellaneous Functions
Description
Section titled “Description”Sets a prefix to prepend to the table name when this model runs SQL queries.
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. In `models/User.cfc`, prepend `tbl` to the default table name so
// Wheels queries the `tblusers` table instead of `users`.
function config() {
setTableNamePrefix("tbl");
}
// 2. Use a schema-style prefix to namespace legacy tables shared across
// multiple applications on the same database.
// models/Order.cfc
component extends="Model" {
function config() {
setTableNamePrefix("legacy_");
// Wheels will now query `legacy_orders` for this model.
}
}