
561
DEVELOPING
COLDFUSION 9 APPLICATIONS
ColdFusion ORM
Las
t
upda
te
d 8/5/2010
<cfproperty
name="fieldname"
fieldtype="one-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"
mappedby="Mapped_Field_name_in_referenced_CFC"
cascade="none"
fetch="join|[select]"
lazy="[true]|false">
Note:
The mappedby attribute can not be specified with the fkcolumn attribute.
Example
In the EMPLOYEE and OFFICECUBICLE example, OFFICECUBICLE has a foreign key column, EMPLOYEEID.
This foreign key references the primary key of the Employee table. OFFICECUBICLE has an auto-generated primary
key, which does not participate in the relationship.
EMPLOYEE.cfc
<cfcomponent persistent="true" table="Employee">
<cfproperty name="EmployeeID" fieldtype="id" generator="native">
<cfproperty name="firstname">
<cfproperty name="lastname">
<cfproperty name="officecubicle" fieldtype="one-to-one" cfc="officecubicle"
mappedby="Employee">
</cfcomponent>
OFFICECUBICLE.cfc
<cfcomponent persistent="true" table="officecubicle">
<cfproperty name="id" fieldtype="id" generator="native">
<cfproperty name="Employee" fieldtype="one-to-one" cfc="Employee" fkcolumn="EmployeeID">
<cfproperty name="Location">
<cfproperty name="Size">
</cfcomponent>
•
In OFFICECUBICLE entity,
fkcolumn="EmployeeID"
specifies that EmployeeID is the foreign key column in
OFFICECUBICLE table.
•
mappedby="Employee"
specifies that the one-to-one relationship is with the foreign-key property 'EMPLOYEE' in
OFFICECUBICLE entity and not with its primary key.
•
In Employee entity, fkcolumn should not be specified.
In this case, OFFICECUBICLE entity has a independent Primary key which is auto-generated.
One-to-many relationship
A one-to-many relationship is where the source object has field that stores a collection of target objects. These target
objects may also have an inverse relationship back to the source object. This relationship is established by having a
foreign key in the target table that maps to the primary key of the source table.
An example of a one-to-many relationship is the relation between artist and art, where the artist has many artwork
pieces.
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...