Adobe COLDFUSION 9 Manual page 565

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
ColdFusion ORM
• Unique Foreign Key association
Primary key association
In this type of association, the primary key of one table references to the primary key of another table. That is, both the
tables share the same primary key.
The following example shows how to define this mapping.
Example
Consider the EMPLOYEE and OFFICECUBICLE example. Both the tables share the same primary key. The mapping
for these tables are as follows:
• EMPLOYEE.cfc
<cfcomponent persistent="true" table="Employee">
<cfproperty name="id" fieldtype="id" generator="native">
<cfproperty name="firstname">
<cfproperty name="lastname">
<cfproperty name="officecubicle" fieldtype="one-to-one" cfc="OfficeCubicle">
</cfcomponent>
• OFFICECUBICLE.cfc
<cfcomponent persistent="true" table="OfficeCubicle">
<cfproperty name="id" fieldtype="id" generator="foreign"
params="{property='Employee'}">
<cfproperty name="Employee" fieldtype="one-to-one" cfc="Employee" constrained="true">
<cfproperty name="Location">
<cfproperty name="Size">
</cfcomponent>
fieldtype=one-to-one
on
constrained=true
Employee
OFFICECUBICLE table for its ID to reference the ID in the EMPLOYEE table.
The ID of EMPLOYEE table is auto-generated. The ID of the OFFICECUBICLE table should be the same as the ID
of the Employee table. For this, set
input, which should be the relationship property name of OFFICECUBICLE entity which is 'EMPLOYEE' in this case.
Here, primary key values of related rows in both the tables must be the same. The identity generator algorithm in
the mapping for the component (whose mapped table has the constraint), must be set to foreign.
Unique foreign key association
In this type of association, the foreign key of one table references the primary key of another table, and the foreign key
column has a unique constraint. To define this relationship,
relationship-property of the CFC whose table contains the foreign key column. The other end of relation should use
attribute.
mappedby
Syntax
specifies that the property is a one-to-one property.
property in OFFICECUBICLE.cfc, means that a constraint is set on the
generator="foreign"
Last updated 8/5/2010
. Foreign generator takes one parameter
attribute should be specified on the
fkcolumn
560
as
'property'

Advertisement

Table of Contents
loading

Table of Contents