
562
DEVELOPING
COLDFUSION 9 APPLICATIONS
ColdFusion ORM
Las
t
upda
te
d 8/5/2010
A one-to-many relationship between two persistent components is defined using the
fieldtype
value
one-to-many
in the
cfproperty
tag. The source object contains a collection of target objects. ColdFusion allows the collection to
be one of the following types:
•
Array
•
Struct
This collection is a persistence aware collection. Any addition or deletion from this collection is automatically persisted
in the database.
Array
An Artist object can contain the Art objects as an array. To define this mapping in the CFC, use the following syntax:
Syntax
<cfproperty
name="field_name"
fieldtype="one-to-many"
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 "
type="array"
orderby="order_by_string"
cascade="cascade_options"
lazy="[true]|false|extra"
fetch="join|[select]"
inverse="true|[false]"
batchsize="N"
optimisticlock="[true]|false"
readonly="true|[false]">
For the artist-art example, the relationship property in Artist.cfc is defined as follows:
<cfproperty name="art" type="array" fieldtype="one-to-many" cfc="Art" fkcolumn="ARTISTID">
•
type-array
specifies that the artist object will contain art objects in an array.
•
fkcolumn="ArtistID"
specifies that the foreign key column is ARTISTID that references the primary key of
ARTIST table.
Struct
An Artist object can contain the Art objects as a struct. The key would be any column in the ART table (usually the
primary key or a unique key). The value would be the Art object. To define this mapping, use the following syntax.
Syntax