
598
DEVELOPING
COLDFUSION 9 APPLICATIONS
ColdFusion ORM
Las
t
upda
te
d 8/5/2010
Note:
If event handlers are defined in both persistent CFC and event handler CFC, the persistent CFC is given the callback
before calling the application wide event handler.
Autogenerating database schema
ColdFusion automatically creates tables when ORM is initialized for the application. For auto-generating tables, do
the following:
In the THIS scope of Application.cfc, in
ormsettings
struct, set the
dbCreate
property to one of the following values:
•
update
: Creates the table (if it does not exist) or updates the table (if it exists).
•
dropcreate
: Drops the table if it exists and then creates it.
For example,
<cfset this.ormsettings.dbCreate="update">
Certain specific attributes (DDL-only attributes) defined for the tags
cfcomponent
and
cfproperty
can be use to
define various attributes for the auto-generated tables and columns. DDL-only attributes are used only for DDL
generation. For details of these attributes, see the table in the section DDL-only attributes in “
Column
” on page 549.
Examples
Application.cfc
<cfset this.name = "AG"/>
<cfset this.ormenabled=true/>
<cfset this.datasource = "ORM_DDL">
<cfset this.ormsettings.dbCreate="dropcreate">
<cfset this.ormsettings.sqlscript="mysqlscript.sql">
Artists.cfc
<cfcomponent persistent="true" table="Artists">
<cfproperty name="artistid" fieldtype="id" ormtype="integer" length=10>
<cfproperty name="firstname" ormtype="string" length="20" notnull="true">
<cfproperty name="lastname" ormtype="string" length="20" notnull="true">
<cfproperty name="address" ormtype="string" length="50">
<cfproperty name="city" ormtype="string" length="20">
<cfproperty name="state" ormtype="string" length="2">
<cfproperty name="postalcode" ormtype="string" length="10">
<cfproperty name="email" ormtype="string" length="50" unique="true">
<cfproperty name="phone" ormtype="string" length="20">
<cfproperty name="fax" ormtype="string" length="12">
<cfproperty name="thepassword" ormtype="string" length="20">
</cfcomponent>
art.cfc