
534
DEVELOPING
COLDFUSION 9 APPLICATIONS
ColdFusion ORM
Las
t
upda
te
d 8/5/2010
The following example explains these concepts by building a simple application, which would enable you to jumpstart
with ColdFusion ORM. The example uses the cfartgallery data source that is shipped as part of ColdFusion 9
documentation option in the installer. The cfartgallery data source has Artists and Art tables. Artists has a one-to-
many relationship with the Art table.
Step 1:
Specify the ORM settings in the Application.cfc file.
The minimum required settings are mentioned in the following sample code snippet:
Application.cfc
<cfset this.name = "ArtGalleryApp">
<cfset this.ormenabled = "true">
<cfset this.datasource = "cfartgallery">
Apart from these, there are other settings that you can use to configure ORM. For details, see “
ORM settings
” on
page 538.
Important:
Define these setting only in Application.cfc and not in Application.cfm.
Step 2:
Map the ARTISTS.cfc to the database table.
1
Create the ARTISTS.cfc.
2
Flag it as a persistent CFC and map it to the ARTISTS table.
To make the ARTISTS.cfc persistent, the
persistent
attribute should be set to
true
in the
cfcomponent
tag. The
table attribute should be set to the table name. If table attribute is not specified, then the CFC name is taken as the
table name.
Each CFC can be given an entity name. Entity name is the name used by the ORM related functions to work with
the persistent CFC. It can be specified by using the
entityname
attribute in
cfcomponent
. If
entityname
is not
specified, then the CFC name is taken as the
entityname
.
3
Now, create properties in ARTISTS.cfc and map them to the columns in the table. One property should be created
for each column in the table. To map the property to the column, the
column
attribute should be set to the
corresponding column name. If the
column
attribute is not specified, then the name of the property is taken as the
column name.
For details on setting the ORM-specific attributes, see “
Define ORM mapping
” on page 542.
The
ARTISTS.cfc
is defined as follows:
<cfcomponent persistent="true">
<cfproperty name="id" column = "ARTISTID" generator="increment">
<cfproperty name="FIRSTNAME">
<cfproperty name="LASTNAME">
<cfproperty name="ADDRESS">
<cfproperty name="CITY">
<cfproperty name="STATE">
<cfproperty name="POSTALCODE">
<cfproperty name="EMAIL">
<cfproperty name="PHONE">
<cfproperty name="FAX">
<cfproperty name="thepassword">
</cfcomponent>
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...