ActiveRecord::StatementInvalid in SearchController#do_search_targets
Mysql::Error: #42S02Table ‘srnadb_chlamy_dev_rails.targets’ doesn’t
exist: SHOW FIELDS FROM targets
Hmm, no doubt you would receive some good help from activerecord gurus
on the rails list.
A couple of thoughts…
An ActiveRecord::Base object needs to have a relation (table) in the
database because many of its methods query the database (AFAIK).
Your instance variables of Target that you set with attr_accessor have
nothing to do with the @attributes variable provided by
ActiveRecord::Base. In fact, you broke the accessor methods Base
provides when you created your instance variables, which is why you
got nil with @targets[0].hit_sequence_ID. The object was returning
the instance variable and not executing the accessor method.
If you don’t specifically need a homemade object to hold your queried
data, you can just…
targets = ActiveRecord::Base.find_by_sql()
I have no idea of your database schema, but you could do this if you
want a Target object…
class Target < ActiveRecord::Base
set_table_name ‘sequence_db’
end
thank you very much for your help. First solution doesn’t work (same
error) but mapping the Target class to sequence_db or hit_sequence
tables, which are involved in the join, works perfectly. I have to
retrieve data not with
targets.first.hit_sequence_ID
but with
targets.first.attributes[‘hit_sequence_ID’]
Thank you again,
Alvaro.
Todd B. wrote:
class Target < ActiveRecord::Base
set_table_name ‘sequence_db’
end