When you build a database centric application, typically you would follow some database standard and naming convention. ColdFusion ORM allows you to define this convention at one central place for the application using the 'naming strategy'. 
The advantage of using a naming strategy is that you do not need to change the code throughout your application. The naming strategy specifies how the table and column have to be named for a CFC and its properties.
Naming strategy takes "logical name" for a table or column and returns the actual table or column name that should be used.

  • Logical table name: This is the table name specified for the CFC. If it is not specified, the entity name is taken as the logical table name. If the entity name is also not specified, the unqualified CFC name, for example, Person for a.b.c.Person, is taken as the logical table name.
  • Logical column name: This is the column name specified for a CFC property. If it is not specified, the property name is taken as the logical column name.
    Naming strategy is applied to an application by setting the following in Application.cfc

    <cfset this.ormsettings.namingstrategy="strategy">

    The value of strategy could be:

  • default: This strategy uses the logical table or column name as it is. ColdFusion ORM using this value as the default strategy.
  • smart: This strategy changes the logical table or column name to uppercase. Also, if the logical table or column name is in camel case, this strategy breaks the camelcased name and separates the broken words using underscore. For example, for a CFC named "OrderProduct", this strategy changes the table name as "ORDER_PRODUCT".
  • your own cfc : You can get complete control of the naming strategy by providing your own implementation. You need to specify the fully qualified name of the CFC as the value for naming strategy. This CFC must implement cfide.orm.INamingStrategy interface.
    The cfide.orm.INamingStrategyinterface is as follows:

    /**
    * Strategy to specify the table name for a CFC and column name for a property in the cfc.
    * This can be used to specify the application specific table and column naming convention.
    * This rule will be applied even if the user has specified the table/column name in the mapping so that
    * the name can be changed for any application at one place without changing the names in all the code.
    */
    interface
    {
    /**
    * Defines the table name to be used for a specified table name. The specified table name is either
    * the table name specified in the mapping or chosen using the entity name.
    */
    public string function getTableName(string tableName);

    /**
    * Defines the column name to be used for a specified column name. The specified column name is either
    * the column name specified in the mapping or chosen using the proeprty name.
    */
    public string function getColumnName(string columnName);
    }

    This interface is specified in the application using:

    this.ormsettings.namingstrategy="com.adobe.UCaseStrategy"

Note: The naming strategy applies to all the table or column names, which you use in the mapping including link table and fkcolumn, even though there is no CFC or cfproperty associated with them.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy