Forum: Ruby on Rails ez-where headscratch

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.
30494933a87bf0f027adc26b9c3238b2?d=identicon&s=25 Bernard Dubuisson (Guest)
on 2006-05-23 17:13
Hi there,
I'm puzzled by this apparently simple query I can't manage to reassemble
using ez_where plugin.

cond = Caboose::EZ::Condition.new :my_table do
   start_on < Time.now
   any {end_on > Time.now; end_on.nil?}
end

I keep getting the following result :

>> cond.to_sql
=> ["my_table.start_on < ? AND (my_table.end_on > ?)", Tue May 23
17:11:43 CEST 2006, Tue May 23 17:11:43 CEST 2006]

while the expected result would be :

["my_table.start_on < ? AND (my_table.end_on > ? OR my_table.end_on IS
NULL)", Tue May 23 17:11:43 CEST 2006, Tue May 23 17:11:43 CEST 2006]

For some reason, ez_where skips the end_on.nil? part, no matter how I
try to formulate it.

Any idea?

Thanks in advance!!
Bernard.
30494933a87bf0f027adc26b9c3238b2?d=identicon&s=25 Bernard Dubuisson (Guest)
on 2006-05-23 21:28
OK, I found myself guilty of not getting deep enough into ezra's test
cases.

Just for the record, this will work :

 cond = Caboose::EZ::Condition.new :my_table do
    start_on < Time.now
    any {end_on > Time.now; end_on == :null}
 end
6076c22b65b36f5d75c30bdcfb2fda85?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2006-05-23 21:42
(Received via mailing list)
On May 23, 2006, at 8:13 AM, Bernard Dubuisson wrote:

> I keep getting the following result :
> For some reason, ez_where skips the end_on.nil? part, no matter how I
> try to formulate it.
>
> Any idea?
>
> Thanks in advance!!
> Bernard.


Hey Bernard-

	The reason it won't work the way you have it written is that inside
the Conditions block ez_where evaluates statements. When you are
putting just end_on.nil? as its own statement ez_where doesn't know
how to handle that so it just drops it out of the query. Let's see if
I can get the results you want with a slightly different syntax:


cond = Caboose::EZ::Condition.new :my_table do
       start_on < Time.now
       any {end_on > Time.now; end_on == :null}
end

Cheers-
-Ezra
D5145c421cd25af6fa577c15219add90?d=identicon&s=25 unknown (Guest)
on 2006-05-23 21:42
(Received via mailing list)
Heh, happened to you too, huh?
-N
This topic is locked and can not be replied to.