OK, so I played with this and got what I wanted. I am including what the SQL query would look like, and how I implemented it with Reactor.
=== SQL QUERY ===
SELECT * FROM mytable
WHERE (field1 LIKE '#myvar#' OR field2 LIKE '#myvar#')
AND field3 = #myothervar#
So, that is what I wanted to do, which as you can see, combines using AND and OR.
With Reactor, here is how I did it.
=== REACTOR IMPLENTATION ===
<!--- Create the gateway and query vars --->
<cfset myGateway = Application.Reactor.createGateway("mytable") />
<cfset query = myGateway.createQuery() />
<!--- Do the first part of the WHERE clause, with the OR --->
<cfset query.getWhere().setMode("OR").isLike("mytable","field1","#myvar#").isLike("mytable","field2","#myvar#") />
<!--- Add in the AND for the second part of the WHERE clause --->
<cfset query.getWhere().setMode("AND").isEqual("mytable","field3",myothervar) />
Let me just say - that is awesome! Just what I was looking for.
Thanks Sean, João and of course, Doug!
Michael
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Sean Corfield
Sent: Tuesday, February 14, 2006 4:10 PM
To: [email protected]
Subject: Re: Reactor For CF Using WHERE and OR
On 2/14/06, João Fernandes <[EMAIL PROTECTED]> wrote:
> <cfset gtw = myreactor.creategateway("mytable")>
> <cfset query = gtw.createquery()>
> <cfset where1 =
> createOBject("component","reactor.query.where").init(query)>
You don't need to create where objects like that! Reactor lets you combine where clauses:
<cfset gtw = myreactor.creategateway("mytable")>
<cfset query = gtw.createquery()>
<cfset where = gtw.getwhere()>
<!--- add first where clause: --->
<cfset where.isLike("mytable","field1",myvar)>
<!--- default mode is 'and' - change it to 'or' ---> <cfset where.setMode("or")>
<!--- add second where clause: --->
<cfset where.isLike("mytable","field2",myvar)>
<!--- execute combined query: --->
<cfset gtw.getByQuery(query)>
--
Sean A Corfield -- http://corfield.org/
Got frameworks?
"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood
-- 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/
