Ez-where headscratch

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.

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

Heh, happened to you too, huh?
-N

On May 23, 2006, at 8:13 AM, Bernard D. 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