Skip to content

Model Configuration

setTableNamePrefix()

setTableNamePrefix() — returns void

Available in: model Category: Miscellaneous Functions

Sets a prefix to prepend to the table name when this model runs SQL queries.

NameTypeRequiredDefaultDescription
prefixstringyes—A prefix to prepend to the table name.
// 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.
	}
}