
564
DEVELOPING
COLDFUSION 9 APPLICATIONS
ColdFusion ORM
Las
t
upda
te
d 8/5/2010
Syntax
<cfproperty
name="fieldname"
fieldtype="many-to-one"
cfc="Referenced_CFC_Name"
linktable="Link table name"
linkcatalog="Catalog for the link table"
linkschema="Schema for the link table"
fkcolumn="Foreign Key column name"
inversejoincolumn="Column name or comma-separated list of primary key columns"
column="Foreign_Key_Column"
mappedby="Mapped_Field_name_in_referenced_CFC"
cascade="cascade_options"
fetch="join|[select]"
lazy="true|false"
insert="[true]|false"
update="[true]|false"
optimisticlock="[true]|false"
missingrowIgnored="true|[false]">
For the art-artist example, the relationship in the ART.cfc can be defined as:
<cfproperty name="artist" fieldtype="many-to-one" fkcolumn="artistid" cfc="Artist">
fkcolumn="ARTISTID"
indicates that the foreign key column in Art table references the primary key ARTISTID of
ARTIST table.
Many-to-many relationships
A many-to-many relationship is where the source objects contain a collection of target objects and the target objects
in turn contain a collection of source objects.
An example of a many-to-many relationship is the relation between Order and Product, where an order has many
products and a product has many orders.
This relationship is established by using a third table called a 'LinkTable'. The LinkTable contains the foreign key to
both the tables participating in the relation. ORM looks for the map key column in the LinkTable and not the target
table.
In the preceding example of Order-Product, a many-to-many relationship is established by using LinkTable.
A many-to-many relationship between two persistent CFCs is defined using the
fieldtype="many-to-many"
value
in the
cfproperty
tag.
Note:
If the fkcolumn name is not specified, ORM generates the fkcolumn name in the "#relationName#_ID" format.
Syntax
Order.cfc