
579
DEVELOPING
COLDFUSION 9 APPLICATIONS
ColdFusion ORM
Las
t
upda
te
d 8/5/2010
This example loads the Artist object with PK 100 and returns the artist object.
<cfset artistobj = EntityLoad('Artist', 100, true)>
Example 3:
This example loads the OrderDetail object which has the composite key OrderID=100 and ProductID=1 and
returns the orderdetail object.
<cfset orderDetail = EntityLoad('orderdetails', {OrderID=100, ProductID=1}, true)>
•
EntityLoad (entityname, filtercriteria [,unique]
Loads and returns an array of entities of the given entity name that matches the
filtercriteria
.
filtercriteria
is a key-value pair (ColdFusion struct) of property names and its values. If there are more than
one key-value pair in
filtercriteria
, then they always use the AND operator. If you are sure that only one record
exists that matches this
filtercriteria
,
unique=true
can be specified so that a single entity is returned instead
of an array. If
unique=true
and multiple records are returned, then an exception occurs. For example, to retrieve
details of all artists that have state ‘CA’:
<cfset artistsFromCA = EntityLoad('Artist', {state="CA"}>
To retrieve a unique object, specify
unique= "true"
. If more than one object satisfies the condition, an exception
occurs.
This example loads the artist object whose firstName is "Austin" and lastname is "Weber".
<cfset artist = EntityLoad('artist', {firstname="Austin", lastname="Weber"}, "true")>
•
EntityLoad(entityname,filtercriteria,sortorder[, options])
Loads and returns an array of entities that satisfy the
filtercriteria
that is sorted as specified by the
sortorder
parameter.
filtercriteria
is a key-value pair (ColdFusion struct) of property names and its values. If there are more than
one key-value pairs in
filtercriteria
, then they always use the AND operator.
sortorder
is a string, and should be specified in the following syntax:
"propname1 asc, propname2 desc, ..."
Some examples of
sortorder
are as follows:
"firstname asc, lastname desc"
"firstname"
"country, age desc"
Example:
To retrieve artists whose state is CA, and sorted by City and FirstName:
<cfset artistsFromCA = EntityLoad('artist', {state="CA"}, "city asc, firstName")>
Certain configuration options can be input as name-value pairs as options argument. Several options can be
specified to control the behavior of entity retrieval.
•
maxResults
: Specifies the maximum number of objects to be retrieved.
•
offset
: Specifies the start index of the resultset from where it has to start the retrieval.
•
cacheable
: Whether the result of this query is to be cached in the secondary cache. Default is false.
•
cachename
: Name of the cache in secondary cache.
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...