Model Class
getTableNamePrefix()
Signature
Section titled “Signature”getTableNamePrefix() — returns string
Available in: model
Category: Miscellaneous Functions
Description
Section titled “Description”Returns the table name prefix that is set for the current model. This is useful when your database tables share a common prefix, and you need to construct queries dynamically or perform operations that require the full table name. By using this function, you ensure consistency and avoid hardcoding table prefixes in your queries.
Examples
Section titled “Examples”1. Get the table name prefix for the current model
prefix = model("user").getTableNamePrefix();
writeOutput("Table prefix: " & prefix);
2. Get the table name prefix for this user when running a custom query.
<cffunction name="getDisabledUsers" returntype="query">
<cfquery datasource="#get('dataSourceName')#" name="local.disabledUsers">
SELECT *
FROM #this.getTableNamePrefix()#users
WHERE disabled = 1
</cfquery>
<cfreturn local.disabledUsers>
</cffunction>