Skip to content

Model Class

getTableNamePrefix()

getTableNamePrefix() — returns string

Available in: model Category: Miscellaneous Functions

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.

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>