DEVELOPING COLDFUSION 9 APPLICATIONS
ColdFusion ORM
Step 3:
Perform CRUD operations.
To retrieve data from the ARTISTS table, use
ARTISTS = EntityLoad("ARTISTS")
All the records from the ARTISTS table are retrieved as an object array.
To add a new artist, create a new artist object and call
<cfscript>
try {
newArtistObj = EntityNew("artists");
newArtistObj.setfirstname("John");
newArtistObj.setlastname("Smith");
newArtistObj.setaddress("5 Newport lane");
newArtistObj.setcity("San Francisco");
newArtistObj.setstate("CA");
newArtistObj.setPostalCode("90012");
newArtistObj.setphone("612-832-2343");
newArtistObj.setfax("612-832-2344");
newArtistObj.setemail("jsmith@company.com");
newArtistObj.setThePassword("jsmith");
EntitySave(newartistobj);
ormflush();
} catch(Exception ex) {
WriteOutput("<p>#ex.message#</p>");
}
</cfscript>
To update an existing record, load that object and make changes to it. ColdFusion automatically detects that the row
for this object needs to be updated and it will get updated when
Note: ORMFlush() is called at the end of the request by default.
In the following code, the
newArtistObj
newArtistObj.setphone("612-832-1111");
ormflush();
To delete a record,
EntityDelete()
EntityDelete(newArtistObj);
ormflush();
Step 4:
Define Relationships
First define the mapping for the ART table to define a relationship between artwork and artists.
The ART.cfc is defined as follows:
:
EntityLoad()
EntitySave()
ORMFlush()
is already managed by ORM, so it does not need to be loaded again.
is used.
Last updated 1/20/2012
for this object.
is called.
535