Hi all ! How I can do like this, because it dosen''t work ? SomethingClass.find(:all, :conditions => ["something_attribute ?",nil]) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 1/25/07, Walde Man <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> How I can do like this, because it dosen''t work ? > SomethingClass.find(:all, :conditions => ["something_attribute > ?",nil])In SQL, you need "something IS NULL" rather than "something = NULL". The above code should have raised a StatementInvalid exception saying as much. Pass conditions as a hash to have Active Record choose whether to use IS NULL for you: SomethingClass.find(:all, :conditions => { :something_attribute => nil }) Or use the find_all_by_* shorthand: SomethingClass.find_all_by_something_attribute(nil) jeremy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jeremy Kemper wrote:> On 1/25/07, Walde Man <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> How I can do like this, because it dosen''t work ? >> SomethingClass.find(:all, :conditions => ["something_attribute >> ?",nil]) > > In SQL, you need "something IS NULL" rather than "something = NULL". > The above code should have raised a StatementInvalid exception saying > as much. > > Pass conditions as a hash to have Active Record choose whether to use > IS NULL for you: > SomethingClass.find(:all, :conditions => { :something_attribute => nil > }) > > Or use the find_all_by_* shorthand: > SomethingClass.find_all_by_something_attribute(nil) > > jeremyThank for help Jeremy ! SomethingClass.find(:all, :conditions => { :something_attribute => nil> }) It work excellently !!!But of course, problem is bigger. When I try do something like that : SomethingClass.find(:all, :conditions => ({ :something_attribute1 => nil> } or { :something_attribute1 => Time.now.mday } ) and ({ :something_attribute2 => nil > } or { :something_attribute2 => Time.now.hour } ) and ({ :something_attribute3 => nil > } or { :something_attribute3 => Time.now.min } ))it doesn''t work again. Could you explain me how I should use "or" and "and" .> })-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 1/25/07, Walde Man <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Jeremy Kemper wrote: > > On 1/25/07, Walde Man <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >> How I can do like this, because it dosen''t work ? > >> SomethingClass.find(:all, :conditions => ["something_attribute > >> ?",nil]) > > > > In SQL, you need "something IS NULL" rather than "something = NULL". > > The above code should have raised a StatementInvalid exception saying > > as much. > > > > Pass conditions as a hash to have Active Record choose whether to use > > IS NULL for you: > > SomethingClass.find(:all, :conditions => { :something_attribute => nil > > }) > > > > Or use the find_all_by_* shorthand: > > SomethingClass.find_all_by_something_attribute(nil) > > > > jeremy > > Thank for help Jeremy ! > SomethingClass.find(:all, :conditions => { :something_attribute => nil > > }) It work excellently !!! > > But of course, problem is bigger. > When I try do something like that : > > SomethingClass.find(:all, :conditions => ({ :something_attribute1 => nil > > } or { :something_attribute1 => Time.now.mday } ) and ({ :something_attribute2 => nil > > } or { :something_attribute2 => Time.now.hour } ) and ({ :something_attribute3 => nil > > } or { :something_attribute3 => Time.now.min } )) > it doesn''t work again. > Could you explain me how I should use "or" and "and" .Check out the ez_where plugin if you''d like to easily translate Ruby''s operators to SQL. jeremy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jeremy Kemper wrote:> On 1/25/07, Walde Man <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > > Check out the ez_where plugin if you''d like to easily translate Ruby''s > operators to SQL. > > jeremyOne more ,thank for help Jeremy ! On another way I apply "IS NULL" in "text form of conditions" instead of "= nil". And with "or" and "and", is great ! ... a thousand thanks ! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---