
599
DEVELOPING
COLDFUSION 9 APPLICATIONS
ColdFusion ORM
Las
t
upda
te
d 8/5/2010
<cfcomponent persistent="true" table="Art">
<cfproperty name="artid" generator="identity" fieldtype="id">
<cfproperty name="artname" ormtype="string" length="50">
<cfproperty name="price" ormtype="double">
<cfproperty name="largeimage" ormtype="string" length="30">
<cfproperty name="mediaid" ormtype="integer" length="10">
<cfproperty name="issold" ormtype="boolean" dbdefault=1>
<cfproperty name="artist" fkcolumn="artistid" fieldtype="many-to-one" cfc="CArtists">
</cfcomponent>
Naming strategy
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.INamingStrategy
interface is as follows: