I''ve been having problems using hashes in conjunction with SQL. Here''s an example: Question.count(:all, :conditions => { :parent => nil }) And here''s the query it runs : SELECT count(*) AS count_all FROM questions WHERE (parent) If I try to do something like: Question.count(:all, :conditions => { :parent => 1 }) I get: Mysql::Error: #42S22Unknown column ''parent1'' in ''where clause'': SELECT count(*) AS count_all FROM questions WHERE (parent1) Why does it strip out the conditional text? I''m running Rails 1.2.3 Thanks in advance for any help! Saxon --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
using hashed conditions only works in 1.2.x i believe. 1.1.6 behavior { :parent => nil } # => select * from ... where (parent) { :parent => 1 } # => select * from ... where (parent1) 1.2.3 behavior { :parent => nil } # => select * from ... where (parent IS NULL) { :parent => 1 } # => select * from ... where (parent = 1) On 4/12/07, Saxon <joeunrue-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I''ve been having problems using hashes in conjunction with SQL. Here''s > an example: > > Question.count(:all, :conditions => { :parent => nil }) > > And here''s the query it runs : > > SELECT count(*) AS count_all FROM questions WHERE (parent) > > If I try to do something like: > > Question.count(:all, :conditions => { :parent => 1 }) > > I get: > > Mysql::Error: #42S22Unknown column ''parent1'' in ''where clause'': > SELECT count(*) AS count_all FROM questions WHERE (parent1) > > Why does it strip out the conditional text? > > I''m running Rails 1.2.3 > > Thanks in advance for any help! > > Saxon > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
sorry, missed that you said you were using 1.2.3. did you create your project using a previous version of rails? if so, check your config/environment.rb file. that will specify which version your project is using. On 4/12/07, Chris Hall <christopher.k.hall-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> using hashed conditions only works in 1.2.x i believe. > > 1.1.6 behavior > > { :parent => nil } # => select * from ... where (parent) > { :parent => 1 } # => select * from ... where (parent1) > > 1.2.3 behavior > > { :parent => nil } # => select * from ... where (parent IS NULL) > { :parent => 1 } # => select * from ... where (parent = 1) > > > On 4/12/07, Saxon <joeunrue-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I''ve been having problems using hashes in conjunction with SQL. Here''s > > an example: > > > > Question.count(:all, :conditions => { :parent => nil }) > > > > And here''s the query it runs : > > > > SELECT count(*) AS count_all FROM questions WHERE (parent) > > > > If I try to do something like: > > > > Question.count(:all, :conditions => { :parent => 1 }) > > > > I get: > > > > Mysql::Error: #42S22Unknown column ''parent1'' in ''where clause'': > > SELECT count(*) AS count_all FROM questions WHERE (parent1) > > > > Why does it strip out the conditional text? > > > > I''m running Rails 1.2.3 > > > > Thanks in advance for any help! > > > > Saxon > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Well don''t I feel silly. I did in fact create the application using 1.1.6, so I updated the number in the environment.rb file and it works just fine. Thank you for your help! Saxon On Apr 12, 1:48 pm, "Chris Hall" <christopher.k.h...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> sorry, missed that you said you were using 1.2.3. > > did you create your project using a previous version of rails? if so, > check your config/environment.rb file. that will specify which > version your project is using. > > On 4/12/07, Chris Hall <christopher.k.h...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > using hashed conditions only works in 1.2.x i believe. > > > 1.1.6 behavior > > > { :parent => nil } # => select * from ... where (parent) > > { :parent => 1 } # => select * from ... where (parent1) > > > 1.2.3 behavior > > > { :parent => nil } # => select * from ... where (parent IS NULL) > > { :parent => 1 } # => select * from ... where (parent = 1) > > > On 4/12/07, Saxon <joeun...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I''ve been having problems using hashes in conjunction with SQL. Here''s > > > an example: > > > > Question.count(:all, :conditions => { :parent => nil }) > > > > And here''s the query it runs : > > > > SELECT count(*) AS count_all FROM questions WHERE (parent) > > > > If I try to do something like: > > > > Question.count(:all, :conditions => { :parent => 1 }) > > > > I get: > > > > Mysql::Error: #42S22Unknown column ''parent1'' in ''where clause'': > > > SELECT count(*) AS count_all FROM questions WHERE (parent1) > > > > Why does it strip out the conditional text? > > > > I''m running Rails 1.2.3 > > > > Thanks in advance for any help! > > > > Saxon--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---