The following works for me: Mymodel.find(:all, :conditions => "fieldOne = ''Example1'' AND myobject_id = ''1''") but when I try Mymodel.find(:all, :conditions => { :fieldOne => Example1, :myobject_id => 1 }) ... I get an error message ActiveRecord::StatementInvalid: Mysql::Error: Unknown column ''fieldOneExample1myobject_id1'' in ''where clause'': SELECT * FROM mymodels WHERE (fieldOneExample1myobject_id1) The section ''Conditions'' in http://api.rubyonrails.org/classes/ActiveRecord/Base.html tells me that using a hash should generate an SQL statement based on equality and AND, but clearly something is not working here. I''m doing these tests using script/console but that shouldn''t make any difference should it? thanks in advance for any help or suggestions! -- 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 8/30/07, Toby Rodwell <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > The following works for me: > > Mymodel.find(:all, :conditions => "fieldOne = ''Example1'' AND myobject_id > = ''1''") > > but when I try > > > Mymodel.find(:all, :conditions => { :fieldOne => Example1, :myobject_id > => 1 })That''s missing quotes around Example1. I suggest you cut and paste your script/console session inputs and outputs exactly, so we can see what''s happening. Using a hash works fine for me, so something else is going on here.> > ... I get an error message > > ActiveRecord::StatementInvalid: Mysql::Error: Unknown column > ''fieldOneExample1myobject_id1'' in ''where clause'': SELECT * FROM mymodels > WHERE (fieldOneExample1myobject_id1) >This looks like the hash is being converted to a string before it''s getting to AR, so we need to see *exactly* what you''re doing. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Here is a raw cut-and-paste from the console question:>> Rtrevent.find(:all, :conditions => "event_type = ''Rteng'' AND router_id = ''1''")=> [#<Rtrevent:0xb750d8b4 @attributes={"event_id"=>"1", "id"=>"5", "router_id"=>"1", "datetime"=>"2007-05-12 18:34:51", "event_type"=>"Rteng"}>, #<Rtrevent:0xb750d878 @attributes={"event_id"=>"2", "id"=>"6", "router_id"=>"1", "datetime"=>"2007-05-12 18:35:51", "event_type"=>"Rteng"}>, #<Rtrevent:0xb750d83c @attributes={"event_id"=>"3", "id"=>"7", "router_id"=>"1", "datetime"=>"2007-05-14 20:00:03", "event_type"=>"Rteng"}>]>> Rtrevent.find(:all, :conditions => { :event_type => ''Rteng'', :router_id => ''1'' } )ActiveRecord::StatementInvalid: Mysql::Error: Unknown column ''event_typeRtengrouter_id1'' in ''where clause'': SELECT * FROM rtrevents WHERE (event_typeRtengrouter_id1) from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:120:in `log'' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:185:in `execute'' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:337:in `select'' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:176:in `select_all'' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:390:in `find_by_sql'' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:924:in `find_every'' from ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:381:in `find'' from (irb):3 -- 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 -~----------~----~----~----~------~----~------~--~---
I would verify that you are running the latest stable version of Ruby on Rails. The hash-based condition clauses were a semi-recent addition to the framework, and judging by the flattening of the hash into a string, my first guess is that that is the case. Taylor Singletary, Reality Technician http://realitytechnicians.com On 8/30/07, Toby Rodwell <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Here is a raw cut-and-paste from the console question: > >> Rtrevent.find(:all, :conditions => "event_type = ''Rteng'' AND router_id = ''1''") > => [#<Rtrevent:0xb750d8b4 @attributes={"event_id"=>"1", "id"=>"5", > "router_id"=>"1", "datetime"=>"2007-05-12 18:34:51", > "event_type"=>"Rteng"}>, #<Rtrevent:0xb750d878 > @attributes={"event_id"=>"2", "id"=>"6", "router_id"=>"1", > "datetime"=>"2007-05-12 18:35:51", "event_type"=>"Rteng"}>, > #<Rtrevent:0xb750d83c @attributes={"event_id"=>"3", "id"=>"7", > "router_id"=>"1", "datetime"=>"2007-05-14 20:00:03", > "event_type"=>"Rteng"}>] > >> Rtrevent.find(:all, :conditions => { :event_type => ''Rteng'', :router_id => ''1'' } ) > ActiveRecord::StatementInvalid: Mysql::Error: Unknown column > ''event_typeRtengrouter_id1'' in ''where clause'': SELECT * FROM rtrevents > WHERE (event_typeRtengrouter_id1) > from > ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:120:in > `log'' > from > ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:185:in > `execute'' > from > ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:337:in > `select'' > from > ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:176:in > `select_all'' > from > ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:390:in > `find_by_sql'' > from > ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:924:in > `find_every'' > from > ./script/../config/../config/../vendor/rails/activerecord/lib/active_record/base.rb:381:in > `find'' > from (irb):3 > > > > > > > > -- > 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 -~----------~----~----~----~------~----~------~--~---