Ray -
This is possible with the oo queries, but it's not elegant. You end up
needing to create two extra where objects for your case. Here's an
(untested) example:
<cfset query = createQuery() />
<cfset where = query.getWhere() />
<!--- create a where statement and set it's mode to "or" --->
<cfset where1 = CreateObject("Component",
"reactor.query.where").init(query).setMode("or") />
<!--- create another where statement. This will implicitly be "and" --->
<cfset where2 = CreateObject("Component", "reactor.query.where").init(query)
/>
<!--- create the first parens --->
<cfset where1.like("object", "fieldA", "xxx") />
<cfset where1.like("object", "fieldB", "xxx") />
<cfset where1.like("object", "fieldC", "xxx") />
<!--- create the second parens --->
<cfset where2.isEqual("object", "regionId", "yyy") />
<cfset where2.isEqual("object", " filetype", "zzz") />
<!--- we want where 1 and where 2 to be true -->
<cfset where.andWhere(where1, where2) />
<!--- we've configured the oo query, run it --->
<cfset results = getByQuery(query) />
That's it!
Of course, it's probably a bit more efficient and easy to simply create and
run your own queries. On the other hand, the above should be cross-db
friendly.
I'm wide open to suggestions on improving this syntax too.
All in all, I'm finding myself using real SQL 95% of the time outside of
core framework.
Doug
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Raymond Camden
Sent: Tuesday, April 25, 2006 4:02 PM
To: [email protected]
Subject: [Reactor For CF] grouping of where clauses
I'm trying to do something that I think should be simple. My query has
3 things it can filter by: Name, RegionID, and FileType. (In reality
there is more, but this should be enough.)
When you search by name, I want to do
where fieldA like XXX OR fieldB like XXX or fieldC like YYY
The regionID and filetype should be simple and direct filters. In SQL
I'd write it like so:
where
(fieldA like '%#xxx#%'
or
fieldB like '%#xxx#%'
or
fieldC like '%#xxx#%')
and regionid = YYY
and filetype = ZZZ
As you can imagine, the important part of this is the parens which
group the ORs. I've got reactor doing everything _but_ the parens. Any
ideas on how I would do this?
--
=======================================================================
Raymond Camden, Director of Development for Mindseye, Inc (www.mindseye.com)
Member of Team Macromedia (http://www.macromedia.com/go/teammacromedia)
Email : [EMAIL PROTECTED]
Blog : ray.camdenfamily.com
Yahoo IM : cfjedimaster
"My ally is the Force, and a powerful ally it is." - Yoda
-- Reactor for ColdFusion Mailing List -- [email protected]
-- Archives at http://www.mail-archive.com/reactor%40doughughes.net/
-- Reactor for ColdFusion Mailing List -- [email protected]
-- Archives at http://www.mail-archive.com/reactor%40doughughes.net/