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. -- Posted via http://www.ruby-forum.com/.
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 -- Posted via http://www.ruby-forum.com/.
On May 23, 2006, at 8:13 AM, Bernard Dubuisson wrote:> 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.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
Heh, happened to you too, huh? -N On 23/05/06, Ezra Zygmuntowicz <ezmobius@gmail.com> wrote:> > On May 23, 2006, at 8:13 AM, Bernard Dubuisson wrote: > > > 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. > > > 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 > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >