
576
DEVELOPING
COLDFUSION 9 APPLICATIONS
ColdFusion ORM
Las
t
upda
te
d 8/5/2010
•
boolean Has<relationship_property_name>()
This method is generated for all the relationships. For one-to-many and many-to-many, this method checks
whether the association collection is empty. If the association collection is empty, it will return true. For one-to-one
and many-to-one, this method checks whether the associated object exists.
•
boolean Has<relationship_property_name>(<associated_object>)
This method is generated for one-to-many and many-to-many relationships. The method checks whether the given
associated object is present in the association collection. If it is present, it returns true.
For
type="array"
, the method signature is
boolean has<relationship_property_name>(<associated_object>)
For
type="struct"
, the method signature is
boolean has<relationship_property_name>(<key>)
Example
Consider the following example of artists (ARTISTS table) and artwork (ART table), where the artist forms a one-to-
many relationship with artwork.
Artist.cfc
<cfcomponent persistent="true" schema="APP" table="Artists">
<cfproperty name="artistid" fieldtype="id"/>
<cfproperty name="firstname"/>
<cfproperty name="lastname"/>
<cfproperty name="state"/>
<cfproperty name="art" fieldtype="one-to-many" cfc="Art" fkcolumn="ArtistID" >
</cfcomponent>
Art.cfc
<cfcomponent persistent="true" schema="APP" table="Art">
<cfproperty name="artid" fieldtype="id"/>
<cfproperty name="artname"/>
<cfproperty name="issold"/>
</cfcomponent>
In this example Artist has a relation field
art
with Art. The following methods are implicitly added to the Artist object:
•
addArts(Art art)
•
booleanremoveArts(Art art)
•
booleanhasArts()
•
booleanhasArts(Art art)
The attribute
singularName
provides the flexibility to change the name of the generated relationship methods. For
example, if the relationship property of Artist is specified as follows:
<cfproperty name="art" fieldtype="one-to-many" cfc="Art" fkcolumn="ArtistID"
singularName="Art">
then the following methods are generated:
•
addArt(Art art)
•
removeArt(Art art)
•
hasArt()
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...