Forum: Ruby on Rails ez_where query question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ef0db53920b243d6758c2f6b1306df0d?d=identicon&s=25 Steve Ross (cwd)
on 2006-04-18 02:36
(Received via mailing list)
I'm having fun composing queries with ez_where, but am stuck on how to
formulate the following using the ez syntax:

(begin_date >= ? OR end_date >= ?) AND (description LIKE ? OR name LIKE
?)

There are two clauses, each containing OR operators (the ez 'any'
syntax)
but both clauses must evaulate to true for a match.

Can anyone suggest the proper way to construct an ez condition that
generates this SQL?

Thanks
--
View this message in context:
http://www.nabble.com/ez_where-query-question-t146...
Sent from the RubyOnRails Users forum at Nabble.com.
6076c22b65b36f5d75c30bdcfb2fda85?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2006-04-18 05:06
(Received via mailing list)
On Apr 17, 2006, at 5:35 PM, s.ross wrote:

>
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails

Hi~

	You can easily get this to work. Something like this:

ez ez $ script/console
Loading development environment.
 >>    cond = Caboose::EZ::Condition.new :my_table do
?>      any { foo == 'bar'; name == 'rails' }
 >>      any { baz! == 'buzz'; name! == 'loob' }
 >>    end
=> #<Caboose::EZ::Condition:0x28ff724 <snip long object dump>]>
 >> cond.to_sql
=> ["(my_table.foo = ? OR my_table.name = ?) AND (my_table.baz != ?
OR my_table.name != ?)", "bar", "rails", "buzz", "loob"]

	So by default when you specify two any commands like this they will
use OR inside the nested parens but it will use AND to join the two
parens groups.

Cheers-
-Ezra
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-04-18 06:28
(Received via mailing list)
On Mon, 2006-04-17 at 17:35 -0700, s.ross wrote:
> I'm having fun composing queries with ez_where, but am stuck on how to
> formulate the following using the ez syntax:
>
> (begin_date >= ? OR end_date >= ?) AND (description LIKE ? OR name LIKE ?)
>
> There are two clauses, each containing OR operators (the ez 'any' syntax)
> but both clauses must evaulate to true for a match.
>
> Can anyone suggest the proper way to construct an ez condition that
> generates this SQL?
----
here's controller code where I use the ez_where and 'or'

  def services_log_residential_all
      cond = Caboose::EZ::Condition.new
      cond.append ["pltype = 'PAH'"], :or
      cond.append ["pltype = '16 Hour'"], :or
    @facility = Facility.find(:all,
      :conditions => cond.to_sql,
      :order => 'name')
    @facility_array = ( @facility.class == Array ? @facility :
[@facility] )
  end

I hope this helps

Craig
Ef0db53920b243d6758c2f6b1306df0d?d=identicon&s=25 Steve Ross (cwd)
on 2006-04-18 06:34
(Received via mailing list)
What I came up with was:

      cond = Caboose::EZ::Condition.new :events do
        any {begin_date >= Date.today; begin_date >= Date.today}
      end

      unless @phrase.nil?
        cond1 = Caboose::EZ::Condition.new :events do  #!! strange code
alert !!
          any {description =~ condition_clause; location =~
condition_clause; state =~ condition_clause}
        end
        cond << cond1
      end
      conditions = cond.to_sql

The reason for the strange code alert is that this line should be:

cond << Caboose::EZ::Condition.new :events do

but for some reason the append operator throws a parse error. Anyhow,
the
code works fine and I'm a happy camper. Thanks Ezra and Craig.
--
View this message in context:
http://www.nabble.com/ez_where-query-question-t146...
Sent from the RubyOnRails Users forum at Nabble.com.
This topic is locked and can not be replied to.