
566
DEVELOPING
COLDFUSION 9 APPLICATIONS
ColdFusion ORM
Las
t
upda
te
d 8/5/2010
Advanced mapping
Collection Mapping
Collection mapping is similar to a one-to-many relationship mapping. However, in collection mapping, you have a
collection of values instead of a collection of persistent target objects.
Consider the Artist-Art tables. If you want each Artist object to contain an array of artwork names instead of artwork
objects, collection mapping should be used.
To define collection mapping in the CFC, use
fieldtype="collection"
in the
cfproperty
tag.
The collection can either be
Array
or
Struct
.
Array
Syntax
name="field_name"
fieldtype="collection"
type="array"
table="table_name"
fkcolumn="foreign_key_column_name"
elementtype="ormtype"
elementColumn="column_name from the link table that should be
used for populating"
orderby="order by string"
lazy = "true|[false]"
readonly="true|[false]"
optimisticlock="[true]|false"
batchsize="batch size">
Example
If each Artist object contains an array of artwork names instead of artwork objects, this mapping can be defined in
Artist.cfc as:
<cfproperty name="artNames" fieldtype="collection" type="array" table="ART"
fkcolumn="ARTISTID" elementcolumn="ARTNAME" elementtype="string">
Attribute
Attribute
Req/Opt
Default
Description
batchsize
Optional
An integer value that specifies the
"
batchsize
" for fetching uninitialized
collections. For details, see
Lazy Loading
.
elementColumn
Required
Specifies the column name that contains
the data to be fetched for collection.
elementtype
Optional
String
Data type of the selected column. See
ORM
data types
for details.
fieldtype
Required
Should be “collection”.