ActiveRecord::StatementInvalid: Mysql::Error: Unknown column
‘fieldOneExample1myobject_id1’ in ‘where clause’: SELECT * FROM mymodels
WHERE (fieldOneExample1myobject_id1)
The section ‘Conditions’ in ActiveRecord::Base 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?
=> 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.
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:inexecute’
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:inselect_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:infind_every’
from
./script/…/config/…/config/…/vendor/rails/activerecord/lib/active_record/base.rb:381:in
`find’
from (irb):3
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.