Hi Phil,

This is a pretty common scenario, and there's a few ways to solve it. 
For something like the SELECT * FROM Orders where you really want
either a customer's orders or a vendor's orders, depending on who is
asking, I'd probably have one of two implementations.

Gateway approach:

I'd have an OrderGateway CFC that had methods like the following:

<!--- shortened to get gist across. --->
<cffunction name="readCustomerOrders">
  <cfargument name="customerId" />
  <cfset var result = "" />
  <cfquery datasource="#getDatasource().getDSN()#" name="result">
    SELECT * FROM Orders WHERE CustomerID = <cfqueryparam
value="#arguments.customerID#" />
  </cfquery>
  <cfreturn result />
</cffunction>

<cffunction name="readVendorOrders">
  <cfargument name="vendorId" />
  <cfset var result = "" />
  <cfquery datasource="#getDatasource().getDSN()#" name="result">
    ... WHERE VendorId = <cfqueryparam value="#arguments.vendorId#" />
  </cfquery>
  <cfreturn result />
</cffunction>


...that's probably the simplist approach, as it gives you a CFC that's
very cohesive, simple to write and simple to use.

Another way is to go the more ORM route, where you could have Vendor
and Customer CFCs with methods like Vendor.getOrders() and
Customer.getOrders(), where getOrders knows to perform the proper type
of query.  Frameworks like Doug Hughes' Reactor can make this easy,
because they take care of the ORM, lazy loading, and "do I want a
query of orders or an array of Order CFCs?" problems.

Does that help?

-Joe


--
Get Glued!
The Model-Glue ColdFusion Framework
http://www.model-glue.com


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]


Reply via email to